Fixing pybind11::bytes()
ambiguous conversion issue.
#2442
Merged
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.
Adding missing
bytes
type totest_constructors()
, to exercise the code change.The changes in the PR were cherry-picked from PR #2409 (with a very minor
modification in test_pytypes.py related to flake8). Via PR #2409, these
changes were extensively tested in the Google environment, as summarized here:
https://docs.google.com/document/d/1TPL-J__mph_yHa1quDvsO12E_F5OZnvBaZlW9IIrz8M/
The changes in this PR did not cause an issues at all.
Note that
test_constructors()
before this PR passes for Python 2 onlybecause
pybind11::str
can holdPyUnicodeObject
orPyBytesObject
. As aside-effect of this PR,
test_constructors()
no longer relies on thispermissive
pybind11::str
behavior. However, the permissive behavior is stillexercised/exposed via the existing
test_pybind11_str_raw_str()
.The test code change is designed to enable easy removal later, when Python 2
support is dropped.
For completeness: confusingly, the non-test code changes travelled through PR
#2340, #2348, and #2409; this is best ignored.
Example
ambiguous conversion
error fixed by this PR: