mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-12 17:26:13 +00:00
fix: enable py::implicitly_convertible<py::none, ...> for py::class_-wrapped types (#3059)
* Allow casting from None to a custom object, closes #2778 * ci.yml patch from the smart_holder branch for full CI coverage.
This commit is contained in:
committed by
Ralf W. Grosse-Kunstleve
parent
cfc06838fd
commit
57a36633c4
@@ -657,12 +657,6 @@ public:
|
||||
PYBIND11_NOINLINE bool load_impl(handle src, bool convert) {
|
||||
if (!src) return false;
|
||||
if (!typeinfo) return try_load_foreign_module_local(src);
|
||||
if (src.is_none()) {
|
||||
// Defer accepting None to other overloads (if we aren't in convert mode):
|
||||
if (!convert) return false;
|
||||
value = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto &this_ = static_cast<ThisT &>(*this);
|
||||
this_.check_holder_compat();
|
||||
@@ -731,7 +725,19 @@ public:
|
||||
}
|
||||
|
||||
// Global typeinfo has precedence over foreign module_local
|
||||
return try_load_foreign_module_local(src);
|
||||
if (try_load_foreign_module_local(src)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Custom converters didn't take None, now we convert None to nullptr.
|
||||
if (src.is_none()) {
|
||||
// Defer accepting None to other overloads (if we aren't in convert mode):
|
||||
if (!convert) return false;
|
||||
value = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user