-
Notifications
You must be signed in to change notification settings - Fork 208
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
[BUG]: std::vector<std::optional<std::string>> behaviour has changed in 2.2.0 #747
Comments
To reproduce this, I downloaded nanobind_example from github, hacked it for the above functions, compiled in Python 3.11; nanobind 2.1.0 and nanobind 2.2.0 |
Ooops. I was thinking that we don't need to explicitly set nullopt in --- a/include/nanobind/stl/detail/nb_optional.h
+++ b/include/nanobind/stl/detail/nb_optional.h
@@ -23,5 +23,6 @@ struct optional_caster {
bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept {
- if (src.is_none())
- // default-constructed value is already empty
+ if (src.is_none()) {
+ value.reset();
return true;
+ } I'll add a test and make a PR. EDIT: |
Problem description
When binding a
std::vector<std::optional<std::string>>
Nones in python become empty strings in C++ in 2.2.0; whereas in 2.1.0 Nones become empty optionals. I suspect this is related to #675Reproducible example code
C++:
Python3:
In 2.1.0 we get:
'foo, bar, baz, NONE, '
In 2.2.0 we get:
'foo, bar, baz, , '
The text was updated successfully, but these errors were encountered: