-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
triageNew bug, unverifiedNew bug, unverified
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
2.12.0
Problem description
If I have some class inheriting from collections.abc
, it would not implicitly cast to corresponding C++ types. Example code shows a reproduction.
This probably makes most sense as nowadays a lot of Python libraries use Mapping/Set
as an abstract type instead of dictionary.
Example code with set follows
Reproducible example code
Python class
from collections.abc import MutableSet
class CaselessSet(MutableSet[str]):
# Using https://stackoverflow.com/a/27531275 as the implementation
# ... implementation not written for brevity
C++ `mymod`
m.def("set_size", [](set<string>& s) {
return s.size();
});
`mymod.pyi`:
from collections.abc import Set as AbstractSet
def set_size(set: AbstractSet[str])
usage:
s = CaselessSet('a', 'B')
mymod.set_size(s)
Is this a regression? Put the last known working version here if it is.
Not a regression
Metadata
Metadata
Assignees
Labels
triageNew bug, unverifiedNew bug, unverified