pybind11
pybind11 copied to clipboard
Support frozenset, tuple as dict keys (alternative approach)
Description
Alternative to #3886 Inspired by https://github.com/pybind/pybind11/discussions/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:
When used as keys (e.g. in std::map), sequence and set types now convert to tuple and frozenset (instead of unhashable list and set).
I am wondering though if there is anyway we can allow users to extend the 'freeze' function for custom Python types, perhaps using template specialization tricks? Thoughts @rwgk @henryiii?
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 https://github.com/pybind/pybind11/pull/3838
Hi @ecatmur is this ready for re-review? (Or are you still working on it?)
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 frozen_type_name) but nothing worked out any better.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Ed Catmur @.> Sent: Friday, May 27, 2022 6:03:44 PM To: pybind/pybind11 @.> Cc: Subscribed @.***> Subject: Re: [pybind/pybind11] Support frozenset, tuple as dict keys (alternative approach) (PR #3887)
Hi @ecatmurhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fecatmur&data=05%7C01%7C%7Cdb2a519803e7418dfdb908da402cc4cf%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637892858269861720%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=7GEWsZpZZUrQYz%2FJT0Gl4AuqCC65I0kIjvu1Tzq3MW8%3D&reserved=0 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 frozen_type_name) but nothing worked out any better.
— Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpybind%2Fpybind11%2Fpull%2F3887%23issuecomment-1140069303&data=05%7C01%7C%7Cdb2a519803e7418dfdb908da402cc4cf%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637892858269861720%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=uM8hdcWZL8ShpgwGiISTtszhsUblU6fzLxcbtaCzkmE%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGEPYHPMLJXO4ESVRVUON33VMFBEBANCNFSM5T2NVLPQ&data=05%7C01%7C%7Cdb2a519803e7418dfdb908da402cc4cf%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637892858269861720%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=HoUxy%2BRtPn75aEUG63rEIryq3LTGSAJjVqnqkw5kfxs%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.***>