nutti / fake-bpy-module

Fake Blender Python API module collection for the code completion.
MIT License
1.3k stars 95 forks source link

bpy.props.EnumProperty items parameter incorrectly typed #246

Closed Road-hog123 closed 3 weeks ago

Road-hog123 commented 1 month ago

My understanding of the documentation is that the items parameter should have the type

collections.abc.Iterable[tuple[str, str, str] | tuple[str, str, str, int] | tuple[str, str, str, str, int] | None]
| collections.abc.Callable[[typing.Any, bpy.types.Context | None], collections.abc.Iterable[tuple[str, str, str] | tuple[str, str, str, int] | tuple[str, str, str, str, int] | None]]

I am happy to create a mod file to enact this change, however I have encountered two issues:

  1. If I type the function's input, then bpy.types needs to be imported to give access to Context
  2. Do I really need to copy the entire function definition into the mod file in order to change one parameter's type?
nutti commented 1 month ago

This is because bpy.types.Context is not processed by DependencyBuilder which resolves the dependency by adding the modules to be imported. https://github.com/nutti/fake-bpy-module/blob/master/src/fake_bpy_module/transformer/dependency_builder.py

If you want to process bpy.types.Context by DependencyBuilder, you need to add ClassRef node to it. So, you may solve this by following code.

collections.abc.Iterable[tuple[str, str, str] | tuple[str, str, str, int] | tuple[str, str, str, str, int] | None]
| collections.abc.Callable[[typing.Any, :class:`bpy.types.Context` | None], collections.abc.Iterable[tuple[str, str, str] | tuple[str, str, str, int] | tuple[str, str, str, str, int] | None]]