nutti / fake-bpy-module

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

Context argument is None in the typing? #292

Closed Andrej730 closed 4 months ago

Andrej730 commented 4 months ago

fake-bpy-module-latest-20240724

I've noticed in a few places that typing is suggesting hat it's possible that provided context will be None:

class Menu:
def poll(cls, context: Context | None) -> bool: ...
def draw(self, context: Context | None): ...
class AssetShelf:
def poll(cls, context: Context | None) -> bool: ...

leading to issues like this:

class VIEW3D_MT_PIE_bim_class(bpy.types.Menu):
    bl_label = "Class"

    @classmethod
    def poll(cls, context):
        if not context.active_object and not context.selected_objects:
            cls.poll_message_set("No object selected.")
            return False
        return True

And it's not just Menu and AssetShelf, there are other places (e.g. UIList.draw_item, UIList.draw_filter) - you can find them by searching Context | None in the bpy\types\__init__.pyi, so it could to be a part of some more general issue.

nutti commented 4 months ago

This relates to #254. I will close this issue and redirect to #254.