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.__getitem__() should accept slice too #154

Closed JonathanPlasse closed 2 months ago

JonathanPlasse commented 7 months ago

bpy_prop_collection.__getitem__() can use slice, but is not present in the type hint.

def __getitem__(self, key: typing.Optional[typing.Union[int, str]]
                    ) -> 'GenericType':
        ''' 

        :param key: 
        :type key: typing.Optional[typing.Union[int, str]]
        :rtype: 'GenericType'
        '''
        ...

Adding slice would fix this issue.

def __getitem__(self, key: typing.Optional[typing.Union[int, str, slice]]
                    ) -> 'GenericType':
        ''' 

        :param key: 
        :type key: typing.Optional[typing.Union[int, str, slice]]
        :rtype: 'GenericType'
        '''
        ...

To fix this, should Blender documentation be updated?

nutti commented 2 months ago

This issue is fixed now.

Road-hog123 commented 1 month ago

When the input to __getitem__ is a slice the return type becomes a tuple, not a single value—is it possible to define overloads in mod files for this purpose?

JonathanPlasse commented 1 month ago

Yes, it is. It has been done for mathutils matmul operators. https://github.com/nutti/fake-bpy-module/blob/1f540cf284a04e09bc36e6766fc911d7cc7a3eec/src/mods/common/analyzer/append/mathutils.mod.rst?plain=1#L135-L150