nutti / fake-bpy-module

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

The true type of array properties is `bpy_prop_array`. #125

Closed angavrilov closed 1 year ago

angavrilov commented 1 year ago

Currently, array properties that don't match any of the mathutils types are represented as typing.List. However the true type is bpy_prop_array[T] | typing.Sequence[T], where bpy_prop_array is a generic wrapper for a C array, similar to existing bpy_prop_collection, and implementing a sequence interface. The documentation declares the type to be 'list of', because it is intended to appear to behave as such, but it is not technically correct: Blender native structures simply cannot have a property that is truly a native list.

The suggested type also includes Sequence directly, because similar to mathutils types (see #124), such fields implicitly cast from native Python sequence types, like list or tuple, when they are assigned a value.

bpy_prop_array appears to have the following attributes: __bool__, __contains__, __delitem__, __doc__, __getattribute__, __getitem__, __iter__, __len__, __repr__, __setitem__, foreach_get, foreach_set (but some like __delitem__ look like they may be dummies that error out).

nutti commented 1 year ago

This enhancement is now merged.