nutti / fake-bpy-module

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

Feature request - support typing for bmesh layers values #288

Open Andrej730 opened 2 months ago

Andrej730 commented 2 months ago

See example below:

import bmesh
from typing import assert_type

bm = bmesh.new()

layer = bm.verts.layers.float.verify()
deform = bm.verts.layers.deform.active

vert = bm.verts[0]
f = vert[layer]
dv = vert[deform]

# It would be nice if it could support those cases:
# "assert_type" mismatch: expected "float" but received "Any"
assert_type(f, float)
# "assert_type" mismatch: expected "BMDeformVert" but received "Any"
assert_type(dv, bmesh.types.BMDeformVert)

# Possibly by adding generics support for BMLayerItem:
assert_type(layer, bmesh.types.BMLayerItem[float])
assert_type(layer, bmesh.types.BMLayerItem[bmesh.types.BMDeformVert])
Road-hog123 commented 2 months ago

Yep, known limitation of #232 :

  • Added __getitem__(), __setitem__() and __delitem__() to BMVert, BMEdge, BMLoop and BMFace.*

*Presently these methods get/set Any—to fix this BMLayerItem needs to be made generic (trivial), but that generic type needs to come from BMLayerCollection which also needs to be made generic, which involves modding all of its methods and uses (non-trivial), and I don't think it's currently possible to bind that generic type to BMLayerItem (but it might be after #161's work on PEP 695 is implemented?).

nutti commented 2 months ago

Created the PR to support this feature. https://projects.blender.org/blender/blender/pulls/125851

After this PR is merged, I will make some classes generic.