-
Notifications
You must be signed in to change notification settings - Fork 2.2k
2.3.0 regression: <class 'bytes'> is not converted to std::vector<uint8_t> anymore #1807
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
Comments
This is an annoying one. Bytes -> vector<uint8_t> would be very natural. |
… to std::vector<uint8_t> anymore
+1 Is there a workaround for this atm (or planned feature)? |
I have been able to use the workaround suggested in #2517, namely: .def("some_func", [](kp::SomeClass &self,
py::bytes &bytes) {
py::buffer_info info(py::buffer(bytes).request());
const char *data = reinterpret_cast<const char *>(info.ptr);
size_t length = static_cast<size_t>(info.size);
self.someFunc(
std::vector<char>(data, data + length)); It seems like having a way to provide a conversion from Python bytes into For my use-case I actually have a function that in cpp is defined as std::vector, but should be able to take a python string and a python bytearray. Because of this, it would be quite useful if this can be supported. Is there a reason why this would not be desired? Would it be due to potential ambiguity? If so, what are the current ambiguous usecases? |
… to std::vector<uint8_t> anymore
… to std::vector<uint8_t> anymore
better to use a string_view or span as the native cast for bytes. zero copy, view only seems like the best fit, imo. |
Will it work "from the box" or anyway custom conversion required ? |
To reproduce, create the following C++ extension:
And invoke it from a Python script like this:
Using
pybind11 2.2.4
, this compiles and runs without errors.Using
pybind11 2.3.0
, this compiles, but produces the following runtime error:This breaking change is not mentioned in the changelog or the upgrade guide.
Version info:
cl.exe
with the/std:c++latest
or/std:c++17
flagThe text was updated successfully, but these errors were encountered: