mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Add additional info to TypeError when C++->Python casting fails (#3605)
* Add additional info to TypeInfo when C++->Python casting fails * Fix typo * Address reviewer comments
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
import env
|
||||
from pybind11_tests import ConstructorStats
|
||||
from pybind11_tests import operators as m
|
||||
|
||||
@@ -135,8 +136,9 @@ def test_overriding_eq_reset_hash():
|
||||
assert m.Comparable(15) is not m.Comparable(15)
|
||||
assert m.Comparable(15) == m.Comparable(15)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
hash(m.Comparable(15)) # TypeError: unhashable type: 'm.Comparable'
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
hash(m.Comparable(15))
|
||||
assert str(excinfo.value).startswith("unhashable type:")
|
||||
|
||||
for hashable in (m.Hashable, m.Hashable2):
|
||||
assert hashable(15) is not hashable(15)
|
||||
@@ -144,3 +146,10 @@ def test_overriding_eq_reset_hash():
|
||||
|
||||
assert hash(hashable(15)) == 15
|
||||
assert hash(hashable(15)) == hash(hashable(15))
|
||||
|
||||
|
||||
def test_return_set_of_unhashable():
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.get_unhashable_HashMe_set()
|
||||
if not env.PY2:
|
||||
assert str(excinfo.value.__cause__).startswith("unhashable type:")
|
||||
|
||||
Reference in New Issue
Block a user