un-iterable fix

This commit is contained in:
Reagan Lee 2023-08-20 14:46:09 -07:00
parent 049eec8474
commit 61133ba83d
3 changed files with 7 additions and 3 deletions

View File

@ -0,0 +1 @@
Removes unhelpful error message from assertion rewrite mechanism when exceptions raised in __iter__ methods, and instead treats them as un-iterable.

View File

@ -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

View File

@ -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: