nutti / fake-bpy-module

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

bpy_prop_collection.get() return type should be Optional[GenericType] #153

Closed JonathanPlasse closed 2 months ago

JonathanPlasse commented 7 months ago

Hi, bpy_prop_collection.get() does not currently have a return type. It should be Optional[GenericType].

nutti commented 2 months ago

This issue is now fixed.

Road-hog123 commented 2 months ago

The return type should be GenericType | DefaultType; Optional[GenericType] is only correct if default is None:

collection.get('missing', collection[0]) should type as GenericType
collection.get('missing', 'example') should type as GenericType | str

nutti commented 2 months ago

@Road-hog123

How should we represent DefaultType in the type annotation?

Road-hog123 commented 2 months ago

Like this I think?

DefaultType = typing.TypeVar("DefaultType")

def get(self, key: str | None, default: DefaultType=None) -> GenericType | DefaultType:
    ...
nutti commented 2 months ago

@Road-hog123

Thanks. Fixed this now.