Skip to content

Commit

Permalink
Handle exception assignment to attribute (py2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lordmauve committed Jun 8, 2019
1 parent d5f5fb2 commit 4f79156
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pep8ext_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ def _extract_names(assignment_target):
if isinstance(assignment_target.name, ast.Tuple):
for name in assignment_target.name.elts:
yield name.id
elif isinstance(assignment_target.name, ast.Attribute):
# Python 2 also supports assigning an exception to an attribute
# eg. except Exception as obj.attr
yield assignment_target.name.attr
else:
yield assignment_target.name.id
else:
Expand Down
18 changes: 18 additions & 0 deletions testsuite/N806_py2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,27 @@ def f():
f()
except (A, B) as (a, b):
pass
#: Okay
def f():
try:
f()
except X, foo:
pass
#: N806
def f():
try:
f()
except (A, B) as (good, BAD):
pass
#: Okay
def f():
try:
f()
except X, foo.bar:
pass
#: N806
def f():
try:
f()
except mod.Timeout, mod.ConnectionError:
pass

0 comments on commit 4f79156

Please sign in to comment.