-
Notifications
You must be signed in to change notification settings - Fork 7
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
Make stl.h list|set|map_caster
more user friendly.
#30045
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…5d5aa09 applied to pywrapcc.
…ertibleTo*()` implementations.
rwgk
changed the title
WIP: Change list_caster (stl.h) to also accept generator objects.
Make stl.h Jul 15, 2023
list|set|map_caster
more user friendly.
…nally consistent with `PyMapping_Check()`
wangxf123456
approved these changes
Jul 17, 2023
include/pybind11/stl.h
Outdated
is that this conversion is not reducing. Implicit conversions of this kind | ||
are also fairly commonly used, therefore enforcing explicit conversions | ||
would have an unfavorable cost : benefit ratio; more sloppily speaking, | ||
such an enforcement would be more annyoing than helpful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annyoing -> annoying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks!
(I'm surprised the pre-commit spell check didn't pick this up.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
pybind/pybind11#4686 applied to pywrapcc.
Snapshot of the pybind/pybind11 PR description as of 2023-07-17 14:27 PDT:
With this PR, it is no longer necessary to explicitly convert Python iterables to
tuple()
,set()
, ormap()
in several common situations, for example:See pybind/pybind11#4686 (comment) below for a more complete demonstration of the behavior differences. (Note that the diff in that comment is reversed, what is
+
here is-
there and vice versa.)This PR strikes a careful compromise between being user friendly and being safe. This compromise was informed by 10s of thousands of use cases in the wild (Google codebase, which includes a very large number of open source third-party packages). Concretely, in connection with PyCLIF-pybind11 integration work, the behaviors of PyCLIF (http://github.com/google/clif) and pybind11 needed to be converged. Originally PyCLIF was extremely far on the permissive side of the spectrum, by accepting any Python iterable as input for a C++
vector
/set
/map
argument, as long as the elements were convertible. The obvious (in hindsight) problem was that any empty Python iterable could be passed to any of these C++ types, e.g.{}
was accpeted for C++vector
/set
arguments, or[]
for C++map
arguments. To fix this, the code base was cleaned up, and gating functions were added to enforce the desired behavior:The exact same gating functions are adopted here. Without this behavior change in pybind11, it would be necessary to insert a very large number of explicit
tuple()
,set()
,map()
conversions in the Google codebase, to complete the PyCLIF-pybind11 integration work. While it is very easy to tell new users to pass e.g.tuple(iterable)
instead ofiterable
, it is not easy to convince hundreds of happy existing PyCLIF users to accept retroactively inserting the explicit conversions. The obvious question that will come back: Why do we have to clutter our code like this? There is no good reason. The exact implementation of the gating functions may seem a little arbitrary at first sight, but is in fact informed by what amounts to a large-scale field experiment, with the originally very permissive behavior of PyCLIF.Suggested changelog entry: