un-iterable fix
This commit is contained in:
parent
049eec8474
commit
61133ba83d
|
@ -0,0 +1 @@
|
||||||
|
Removes unhelpful error message from assertion rewrite mechanism when exceptions raised in __iter__ methods, and instead treats them as un-iterable.
|
|
@ -132,7 +132,7 @@ def isiterable(obj: Any) -> bool:
|
||||||
try:
|
try:
|
||||||
iter(obj)
|
iter(obj)
|
||||||
return not istext(obj)
|
return not istext(obj)
|
||||||
except TypeError:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -689,16 +689,19 @@ class TestAssertionRewrite:
|
||||||
def f() -> None:
|
def f() -> None:
|
||||||
class A:
|
class A:
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
raise TypeError("user message")
|
raise ValueError()
|
||||||
|
|
||||||
def __eq__(self, o: object) -> bool:
|
def __eq__(self, o: object) -> bool:
|
||||||
return self is o
|
return self is o
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<A object>"
|
||||||
|
|
||||||
assert A() == A()
|
assert A() == A()
|
||||||
|
|
||||||
msg = getmsg(f)
|
msg = getmsg(f)
|
||||||
assert msg is not None
|
assert msg is not None
|
||||||
assert "Unexpected exception" in msg
|
assert "<A object> == <A object>" in msg
|
||||||
|
|
||||||
def test_formatchar(self) -> None:
|
def test_formatchar(self) -> None:
|
||||||
def f() -> None:
|
def f() -> None:
|
||||||
|
|
Loading…
Reference in New Issue