Commit b8ec6e42 authored by Vincent A's avatar Vincent A

tools/hooks/check-trailing-commas.py: don't crash with {**foo}

A star-mapping in a dict returns a None key.
parent b862de3e
......@@ -101,7 +101,14 @@ class TrailingCommaVerifier(Checker, ast.NodeVisitor):
if self.should_skip(node, attr):
return
first_elt_token = getattr(node, attr)[0].first_token
if getattr(node, attr)[0]:
first_elt_token = getattr(node, attr)[0].first_token
else:
assert isinstance(node, ast.Dict) and attr == 'keys', "None node should only be in dict keys"
# a None node in ast.Dict.keys happens in case of **mapping
# use the tokens of the value then, nevermind the "**" tokens
first_elt_token = node.values[0].first_token
if first_elt_token.start[0] == node.first_token.start[0]:
self.add_error(
'first element should start on a new line',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment