-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support frozenset, tuple as dict keys (alternative approach) #3887
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
base: master
Are you sure you want to change the base?
Conversation
pybind#3836 Add frozenset as a pybind11 type. Add freeze() function converting set to frozenset and list to tuple; use it in std::set and std::map casters. Add tests.
Hmm, also I noticed the freeze PEP was rejected as bugprone. Really this is a symptom of us needing to have better specialization and user configuration of key / value converters. Related to the issue we have found in #3838 |
For the reverse direction, std::set still casts to set. This is in concordance with the behavior for sequence containers, where e.g. tuple casts to std::vector but std::vector casts to list. Extracted from pybind#3886.
since this will be part of pybind11 public API
and rename anyset methods
Making frozenset non-default constructible means that we need to adjust pyobject_caster to not require that its value is default constructible, by initializing value to a nil handle. This also allows writing C++ functions taking anyset, and is arguably a performance improvement, since there is no need to allocate an object that will just be replaced by load. Add some more tests, including anyset::empty, anyset::size, set::add and set::clear.
for more information, see https://pre-commit.ci
Hi @ecatmur is this ready for re-review? (Or are you still working on it?) |
Sorry, yeah. I was exploring some alternate approaches (I don't particularly like |
Description
Alternative to #3886
Inspired by #3836
Add frozenset as a pybind11 type.
Add freeze() function converting set to frozenset and list to tuple; use
it in std::set and std::map casters.
Add tests.
Suggested changelog entry: