Casting from an unregistered type does not throw.
Open
@YannickJadoul is already working on this.
Since Jul 28, 2020.
bug
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Hello,
Issue description
I have this issue on pybind11 v2.5.0.
In the documentation, in object.rst, section Casting back and forth, the following is stated:
When conversion fails, both directions throw the exception cast_error.
But when trying to cast an unregistered custom type, it does not. Instead it seems to be setting an error (PyErr_Occurred returns a TypeError) and it returns a None object.
Reproducible example code
#include <pybind11/pybind11.h>
#include <pybind11/embed.h>
#include <cassert>
struct F {};
int main() {
pybind11::scoped_interpreter interp;
F f;
try {
auto obj = pybind11::cast(f);
}
catch(...) {
return 0;
}
assert(((void)"cast did not throw an exception", false));
return -1;
}
According to the documentation, we should not get an assertion failure with this code.
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.
Assessment
This issue has not been assessed yet.