New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash on unexpected PY2 except syntax #4011

Merged
merged 5 commits into from Sep 26, 2017
Jump to file or symbol
Failed to load files and symbols.
+7 −6
Diff settings

Always

Just for now

View
@@ -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 <expr>, <anything but a name>` 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]
ProTip! Use n and p to navigate between commits in a pull request.