nutti / fake-bpy-module

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

Update: Improve mathutils typing #238

Closed JonathanPlasse closed 1 month ago

JonathanPlasse commented 1 month ago

Purpose of the pull request

Description about the pull request

Use descriptors to type the behavior of Blender when using `mathutils.(Vector|Color|Euler|Quaternion|Matrix). When getting an attribute, the obtain type is the mathutils type. But when setting an attribute, it either accepts a sequence or the type of the attribute.

When used as a function argument, we have to specify that it either accept a sequence or the mathutils type, as descriptors only apply to classes.

For Vector, Color, Euler, and Quaternion the sequence type is Sequence[float]. For Matrix the sequence type is Sequence[Sequence[float]].

Sequence[float] is used instead of list[float] | tuple[float, float, float] as it encapsulates it while still being correct.

In #158, @Road-hog123 proposed to use a protocol instead of Sequence to allow numpy arrays. I will leave this for another PR.

nutti commented 1 month ago

The build error is now fixed. Could you rebase to master branch?

nutti commented 1 month ago

@JonathanPlasse Thank you for your effort. This greatly improves fake-bpy-module.

JonathanPlasse commented 1 month ago

Thank you for your feedback.