Skip to content

Conversion from bytes() to std::string #816

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

Closed
daid opened this issue Apr 26, 2017 · 1 comment
Closed

Conversion from bytes() to std::string #816

daid opened this issue Apr 26, 2017 · 1 comment

Comments

@daid
Copy link

daid commented Apr 26, 2017

Issue description

Conversion from bytes() from python to std::string should be automatic according to the documentation at:
http://pybind11.readthedocs.io/en/master/advanced/cast/strings.html#passing-bytes-to-c

However, when I actually have a function that accepts std::string, passing a bytes object causes a TypeError.

python 3.4.2
pybind11 git hash deb85f4
gcc: arm-linux-gnueabihf-gcc ( 4.9.2-10) 4.9.2

With py::bytes also being available, I'm not sure if this is a bug in the code or an error in the documentation.

Reproducible example code

#include <pybind11/pybind11.h>

namespace py = pybind11;

void test(const std::string& s) {
}

PYBIND11_PLUGIN(example) {
    py::module m("example", "pybind11 example plugin");
    m.def("test", &test, "");
    return m.ptr();
}
import example
example.test('x') # works
example.test(b'x') # TypeError
@jagerman
Copy link
Member

Definitely looks like a bug. (I also just checked--it doesn't affect Python 2, where it would probably be much more noticeable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants