Skip to content

Commit 20d0c72

Browse files
pdmccormickgnprice
authored andcommitted
Test that we only accept a flat tuple of types in except statements (#1624)
Follow-up to new handling from #1610.
1 parent 9982db6 commit 20d0c72

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mypy/test/data/check-statements.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ try:
559559
except (E1, E2): pass
560560
except (E1, object): pass # E: Exception type must be derived from BaseException
561561
except (object, E2): pass # E: Exception type must be derived from BaseException
562+
except (E1, (E2,)): pass # E: Exception type must be derived from BaseException
563+
564+
except (E1, E2): pass
565+
except ((E1, E2)): pass
566+
except (((E1, E2))): pass
562567
[builtins fixtures/exception.py]
563568

564569
[case testExceptWithMultipleTypes2]
@@ -656,6 +661,10 @@ except exs2 as e2:
656661
a = e2 # type: E1
657662
b = e2 # type: E1_1 # E: Incompatible types in assignment (expression has type "Union[E1_1, E1_2]", variable has type "E1_1")
658663
c = e2 # type: E1_2 # E: Incompatible types in assignment (expression has type "Union[E1_1, E1_2]", variable has type "E1_2")
664+
665+
exs3 = (E1, (E1_1, (E1_2,)))
666+
try: pass
667+
except exs3 as e3: pass # E: Exception type must be derived from BaseException
659668
[builtins fixtures/exception.py]
660669

661670
[case testInvalidTupleValueAsExceptionType]

0 commit comments

Comments
 (0)