2.3.0 regression: <class 'bytes'> is not converted to std::vector<uint8_t> anymore
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
To reproduce, create the following C++ extension:
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <vector>
#include <stdint.h>
void take_bytes(const std::vector<uint8_t> &raw) {}
PYBIND11_MODULE(my_ext, m) {
m.def("take_bytes", &take_bytes);
}
And invoke it from a Python script like this:
import my_ext
my_ext.take_bytes(b'hello')
Using pybind11 2.2.4, this compiles and runs without errors.
Using pybind11 2.3.0, this compiles, but produces the following runtime error:
Traceback (most recent call last):
...
File "hello.py", line 2, in <module>
my_ext.take_bytes(b'hello')
TypeError: take_bytes(): incompatible function arguments. The following argument types are supported:
1. (arg0: List[int]) -> None
This breaking change is not mentioned in the changelog or the upgrade guide.
Version info:
- Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
- Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27026.1 for x64
- I'm running
cl.exewith the/std:c++latestor/std:c++17flag
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the shown C++ extension and running the Python take_bytes(b'hello') reproduction with pybind11 2.3.0, then compare the conversion behavior with 2.2.4. Trace the std::vector<uint8_t> argument conversion from the take_bytes entry point. Done means the bytes call works again, with the breaking change also recorded in docs/changelog.rst or docs/upgrade.rst.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100