Closed angavrilov closed 1 year ago
I actually checked the code, and basically:
Iterable[float]
, because they use PySequence_Fast
(with special cases for all mathutils types for performance). All mathutils types are iterable.PySequence_Size
and PySequence_GetItem
, and will accept any sequence. All mathutils types are sequences in this sense (but PyCharm currently doesn't seem to recognize them as compatible with typing.Sequence
for whatever reason).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.
This enhancement is now merged.
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.