Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - support typing for bmesh layers values #288

Open
Andrej730 opened this issue Jul 10, 2024 · 2 comments
Open

Feature request - support typing for bmesh layers values #288

Andrej730 opened this issue Jul 10, 2024 · 2 comments

Comments

@Andrej730
Copy link
Contributor

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 Andrej730 changed the title Feature request - support typing for bmesh layers Feature request - support typing for bmesh layers values Jul 10, 2024
@Road-hog123
Copy link
Contributor

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 nutti self-assigned this Aug 4, 2024
@nutti
Copy link
Owner

nutti commented Aug 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants