fake-bpy-module icon indicating copy to clipboard operation
fake-bpy-module copied to clipboard

Feature request - support typing for bmesh layers values

Open Andrej730 opened this issue 1 year ago • 2 comments
trafficstars

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])

Andrej730 avatar Jul 10 '24 12:07 Andrej730

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?).

Road-hog123 avatar Jul 10 '24 13:07 Road-hog123

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.

nutti avatar Aug 04 '24 06:08 nutti

The PR is now merged. Then, I will start to tackle this issue from fake-bpy-module side.

nutti avatar Oct 09 '24 12:10 nutti

This feature is now supported. Close this issue.

nutti avatar Oct 10 '24 11:10 nutti