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:
Cris Luengo
2021-06-25 18:56:17 -06:00
committed by GitHub
parent 484b0f0433
commit 93e69191c1
4 changed files with 55 additions and 20 deletions

View File

@@ -431,6 +431,17 @@ def test_accepts_none(msg):
assert "incompatible function arguments" in str(excinfo.value)
def test_casts_none(msg):
"""#2778: implicit casting from None to object (not pointer)"""
a = m.NoneCastTester()
assert m.ok_obj_or_none(a) == -1
a = m.NoneCastTester(4)
assert m.ok_obj_or_none(a) == 4
a = m.NoneCastTester(None)
assert m.ok_obj_or_none(a) == -1
assert m.ok_obj_or_none(None) == -1
def test_str_issue(msg):
"""#283: __str__ called on uninitialized instance when constructor arguments invalid"""