File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1+ Removes unhelpful error message from assertion rewrite mechanism when exceptions raised in __iter__ methods, and instead treats them as un-iterable.
Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ def isiterable(obj: Any) -> bool:
132132 try :
133133 iter (obj )
134134 return not istext (obj )
135- except TypeError :
135+ except Exception :
136136 return False
137137
138138
Original file line number Diff line number Diff line change @@ -685,6 +685,25 @@ def myany(x) -> bool:
685685 assert msg is not None
686686 assert "<MY42 object> < 0" in msg
687687
688+ def test_assert_handling_raise_in__iter__ (self , pytester : Pytester ) -> None :
689+ pytester .makepyfile (
690+ """\
691+ class A:
692+ def __iter__(self):
693+ raise ValueError()
694+
695+ def __eq__(self, o: object) -> bool:
696+ return self is o
697+
698+ def __repr__(self):
699+ return "<A object>"
700+
701+ assert A() == A()
702+ """
703+ )
704+ result = pytester .runpytest ()
705+ result .stdout .fnmatch_lines (["*E*assert <A object> == <A object>" ])
706+
688707 def test_formatchar (self ) -> None :
689708 def f () -> None :
690709 assert "%test" == "test" # type: ignore[comparison-overlap]
You can’t perform that action at this time.
0 commit comments