Skip to content

Commit

Permalink
Merge pull request #100 from jparise/excepthandler-tuple
Browse files Browse the repository at this point in the history
Support tuples of ast.ExceptHandler names
  • Loading branch information
jparise committed Jan 29, 2019
2 parents 2a3f58f + 76d14bb commit 9596c43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/pep8ext_naming.py
Expand Up @@ -454,8 +454,7 @@ def _extract_names(assignment_target):
target_type = type(assignment_target)
if target_type is ast.Name:
yield assignment_target.id
return
if target_type in (ast.Tuple, ast.List):
elif target_type in (ast.Tuple, ast.List):
for element in assignment_target.elts:
element_type = type(element)
if element_type is ast.Name:
Expand All @@ -466,13 +465,16 @@ def _extract_names(assignment_target):
elif not PY2 and element_type is ast.Starred: # PEP 3132
for n in _extract_names(element.value):
yield n
return
if target_type is ast.ExceptHandler:
elif target_type is ast.ExceptHandler:
if PY2:
yield assignment_target.name.id
# Python 2 supports unpacking tuple exception values.
if isinstance(assignment_target.name, ast.Tuple):
for name in assignment_target.name.elts:
yield name.id
else:
yield assignment_target.name.id
else:
yield assignment_target.name
return


def is_mixed_case(name):
Expand Down
13 changes: 13 additions & 0 deletions testsuite/N806_py2.py
@@ -0,0 +1,13 @@
# python_version < '3'
#: Okay
def f():
try:
f()
except (A, B) as (a, b):
pass
#: N806
def f():
try:
f()
except (A, B) as (good, BAD):
pass

0 comments on commit 9596c43

Please sign in to comment.