From 698a59cfc99c7a2d969b9ff794410742ff8dde50 Mon Sep 17 00:00:00 2001 From: Peter McCormick Date: Thu, 2 Jun 2016 21:16:38 -0400 Subject: [PATCH] Only accept a flat tuple of types in `except` statements Follow-up to new handling from #1610. --- mypy/test/data/check-statements.test | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mypy/test/data/check-statements.test b/mypy/test/data/check-statements.test index b046bb2847c2..1ab6f5f4a01e 100644 --- a/mypy/test/data/check-statements.test +++ b/mypy/test/data/check-statements.test @@ -559,6 +559,11 @@ try: except (E1, E2): pass except (E1, object): pass # E: Exception type must be derived from BaseException except (object, E2): pass # E: Exception type must be derived from BaseException +except (E1, (E2,)): pass # E: Exception type must be derived from BaseException + +except (E1, E2): pass +except ((E1, E2)): pass +except (((E1, E2))): pass [builtins fixtures/exception.py] [case testExceptWithMultipleTypes2] @@ -656,6 +661,10 @@ except exs2 as e2: a = e2 # type: E1 b = e2 # type: E1_1 # E: Incompatible types in assignment (expression has type "Union[E1_1, E1_2]", variable has type "E1_1") c = e2 # type: E1_2 # E: Incompatible types in assignment (expression has type "Union[E1_1, E1_2]", variable has type "E1_2") + +exs3 = (E1, (E1_1, (E1_2,))) +try: pass +except exs3 as e3: pass # E: Exception type must be derived from BaseException [builtins fixtures/exception.py] [case testInvalidTupleValueAsExceptionType]