diff --git a/mypy/fastparse2.py b/mypy/fastparse2.py index e6d9f7ca3c00..3156f9eac728 100644 --- a/mypy/fastparse2.py +++ b/mypy/fastparse2.py @@ -586,15 +586,16 @@ def try_handler(self, orelse: List[ast27.stmt], finalbody: List[ast27.stmt], lineno: int) -> TryStmt: - def produce_name(item: ast27.ExceptHandler) -> Optional[NameExpr]: + vs = [] # type: List[Optional[NameExpr]] + for item in handlers: if item.name is None: - return None + vs.append(None) elif isinstance(item.name, ast27.Name): - return NameExpr(item.name.id) + vs.append(NameExpr(item.name.id)) else: - raise RuntimeError("'{}' has non-Name name.".format(ast27.dump(item))) - - vs = [produce_name(h) for h in handlers] + self.fail("Sorry, `except , ` is not supported", + item.lineno, item.col_offset) + vs.append(None) types = [self.visit(h.type) for h in handlers] handlers_ = [self.as_required_block(h.body, h.lineno) for h in handlers] diff --git a/test-data/unit/check-python2.test b/test-data/unit/check-python2.test index 5f1258f3b769..f1064125a734 100644 --- a/test-data/unit/check-python2.test +++ b/test-data/unit/check-python2.test @@ -77,6 +77,21 @@ except BaseException, e: e() # E: "BaseException" not callable [builtins_py2 fixtures/exception.pyi] +[case testTryExceptUnsupported] +try: + pass +except BaseException, (e, f): # E: Sorry, `except , ` is not supported + pass +try: + pass +except BaseException, [e, f, g]: # E: Sorry, `except , ` is not supported + pass +try: + pass +except BaseException, e[0]: # E: Sorry, `except , ` is not supported + pass +[builtins_py2 fixtures/exception.pyi] + [case testAlternateNameSuggestions] class Foo(object): def say_hello(self):