Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add W605: Use 'as' over comma when catching exceptions #177

Closed
wants to merge 1 commit into from

2 participants

@rconradharris

No description provided.

@florentx
Collaborator

This change is not compatible with Python 2.5.

However it could be implemented as an extension to flake8. See discussion on issue #175.

@florentx florentx closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 0 deletions.
  1. +16 −0 pep8.py
  2. +5 −0 testsuite/W60.py
View
16 pep8.py
@@ -93,6 +93,7 @@
INDENT_REGEX = re.compile(r'([ \t]*)')
RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,')
+EXCEPT_COMMA_TARGET_IDENTIFIER_REGEX = re.compile(r'except\s+\w+\s*,')
RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,\s*\w+\s*,\s*\w+')
ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b')
DOCSTRING_REGEX = re.compile(r'u?r?["\']')
@@ -1005,6 +1006,21 @@ def python_3000_backticks(logical_line):
yield pos, "W604 backticks are deprecated, use 'repr()'"
+def python_3000_catching_exceptions(logical_line):
+ """
+ Commas to delineate exception identifier targets are removed in Python 3.
+ Use 'as' instead.
+
+ Okay: except DummyError as exc:
+ Okay: except (DummyError, AnotherError):
+ W605: except DummyError, exc:
+ """
+ match = EXCEPT_COMMA_TARGET_IDENTIFIER_REGEX.match(logical_line)
+ if match:
+ yield (match.end() - 1, "W605 commas to delineate exception "
+ " identifier targets are deprecated, use 'as'")
+
+
##############################################################################
# Helper functions
##############################################################################
View
5 testsuite/W60.py
@@ -12,3 +12,8 @@
x = 0
#: W604
val = `1 + 2`
+#: W605
+try:
+ pass
+except KeyError, exc:
+ pass
Something went wrong with that request. Please try again.