You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: stl_bind generates invalid type signature for Sphinx/Pylance #3986
STL_bind creates subclasses that try to mimic keyview. However, our subclasses have no explicit relation with typing.collections.KeyView or collection.abc.KeyView etc... #3985 attempts to fix it by removing the [], but this seems like a cludge and we really should let the typing system represent these as the correct type. I am wondering if there is a way we can still have Sphinx / Pylance recognize these KeyView, ItemViews etc as what they are instead of just an opaque class. Maybe just having them inherit from / mixin collections.abc.KeyViews would be appropiate?
@bmerry Since you created the original PR for this feature, any thoughts on if there is a clever way to solve this issue?
No, no clever ideas. I don't think I've touched pybind11 since I wrote that code, and I think the square bracket convention predated the changes I made.
The current naming with e.g. KeysView[BindedMap] also prevents formatting the stubs with black, because it stumbles on the IMO incorrect Python syntax. Is there a reason against a name with valid syntax such as KeysViewBindedMap?
I guess the reason to inherit the class from e.g. collections.abc.KeysView would be to allow checking its capability with something like this:
ld: illegal text reloc in '__ZN8pybind118bind_mapINSt3__113unordered_mapINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE9LocalBaseILi0EENS1_4hashIS8_EENS1_8equal_toIS8_EENS6_INS1_4pairIKS8_SA_EEEEEENS1_10unique_ptrISJ_NS1_14default_deleteISJ_EEEEJEEENS_6class_IT_JT0_EEENS_6handleERSG_DpOT1_' to '__ZN8pybind116detail13string_casterINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEELb0EE4nameE' for architecture x86_64
Thoughts @rwgk@henryiii on how to fix this? It seems like the culprit its converting the descr compiletime string into a runtime one.
Is the name used for anything other than rendering documentation? If not, then I don't see why we can't allow duplicates. If so, then add the ability to specify both an 'actual' internal name and a doc-only name used for rendering docs.
Activity
Skylion007 commentedon Jun 2, 2022
@bmerry Since you created the original PR for this feature, any thoughts on if there is a clever way to solve this issue?
bmerry commentedon Jun 2, 2022
No, no clever ideas. I don't think I've touched pybind11 since I wrote that code, and I think the square bracket convention predated the changes I made.
odel4y commentedon Oct 21, 2022
The current naming with e.g.
KeysView[BindedMap]also prevents formatting the stubs with black, because it stumbles on the IMO incorrect Python syntax. Is there a reason against a name with valid syntax such asKeysViewBindedMap?I guess the reason to inherit the class from e.g.
collections.abc.KeysViewwould be to allow checking its capability with something like this:If so, could this be done with creating a Python class like #1193 (comment) or specifically indicating the base class like #1193 (comment) ?
Skylion007 commentedon Oct 23, 2022
I actually figured that there is a typing.KeysView etc.. that we can use. However, we need to specify the keytype, value_type.
Whenever I insert the following line into stl_bind.h, it gives a linker error though for Clang:
error:
Thoughts @rwgk @henryiii on how to fix this? It seems like the culprit its converting the descr compiletime string into a runtime one.
Skylion007 commentedon Oct 23, 2022
I found a workaround to the linker error, but if I fix the typing system, we get an error because we define the same classname multiple times:
diff:
Error:
virtuald commentedon Oct 25, 2022
Is the name used for anything other than rendering documentation? If not, then I don't see why we can't allow duplicates. If so, then add the ability to specify both an 'actual' internal name and a doc-only name used for rendering docs.