nutti / fake-bpy-module

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

Vector parameters should accept Python sequences. #124

Closed angavrilov closed 1 year ago

angavrilov commented 1 year ago

All native functions with mathutils parameters (Vector, Quaternion, Color, I think Matrix too) also accept native Python sequences (list, tuple) of float values of the correct size. This implicit cast is implemented in internal C utility functions used to decode such parameters. The same is true when assiging a value to Vector etc fields.

Therefore, as a universal rule such parameters and fields should be rendered as Vector | typing.Sequence[float], Quaternion | typing.Sequence[float], Matrix | typing.Sequence[typing.Sequence[float]] etc. Function return types on the other hand should be exact.

Also, the types themselves should support being used as a sequence, supporting read/write [], len, and Iterable.

angavrilov commented 1 year ago

I actually checked the code, and basically:

I.e. using specific Vector, Quaternion etc types is important for return values (and documentation of parameter purpose), but inputs like function parameters and assigning to fields are actually very permissive in what they accept.

So ideally Vector, Quaternion etc should somehow be made to be recognized as Sequence[float]. Then parameters using Sequence in the type would correctly accept all compatible types.

nutti commented 1 year ago

This enhancement is now merged.