summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomer Keren <tomer.keren.dev@gmail.com>2018-12-08 01:37:22 +0200
committerIan Stapleton Cordasco <graffatcolmingov@gmail.com>2018-12-07 17:37:22 -0600
commitbd17ca651a57f8cdd278a8fac84d6a09a178a3eb (patch)
treeb85f003fd09f9f814345b58546e05bf644ba4518
parentc507b725d9e0bed14505f87cd2397ac7ac489485 (diff)
downloadpep8-bd17ca651a57f8cdd278a8fac84d6a09a178a3eb.tar.gz
Add whitespace around -> annotating operator (#809)
* Test for whitespace around -> operator Tests will pass after fixing issue #803 * Require whitespace around -> operator Closes: #803 * Move tests to correct cases * Whitelist python3 only tests * Fix whitespace test errors Huge thanks to @asottile! * Address code review Pushing this directly to run full testsuite on travis * :bug:Change error code to space around bitwise operator E227 * Check for -> annotation only in py3.5+ * Skip tests meant for higher versions of python * Move type annotation tests to python3.5 testsuite Type annotations were first introduced in PEP 484,https://www.python.org/dev/peps/pep-0484/ implemented in python3.5 * Shorten line skipping tests by version * Replace test skipping logic As requested in code review * Run formatting to avoid long lines
-rwxr-xr-xpycodestyle.py5
-rw-r--r--testsuite/python35.py6
-rw-r--r--testsuite/support.py7
3 files changed, 17 insertions, 1 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 73f4076..4372e3b 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -115,9 +115,12 @@ KEYWORDS = frozenset(keyword.kwlist + ['print', 'async']) - SINGLETONS
UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-'])
WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])
+# Warn for -> function annotation operator in py3.5+ (issue 803)
+FUNCTION_RETURN_ANNOTATION_OP = ['->'] if sys.version_info >= (3, 5) else []
WS_NEEDED_OPERATORS = frozenset([
'**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
- '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='])
+ '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='] +
+ FUNCTION_RETURN_ANNOTATION_OP)
WHITESPACE = frozenset(' \t')
NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT])
diff --git a/testsuite/python35.py b/testsuite/python35.py
new file mode 100644
index 0000000..1bedee5
--- /dev/null
+++ b/testsuite/python35.py
@@ -0,0 +1,6 @@
+#: E225
+def bar(a, b)->int:
+ pass
+#: Okay
+def baz(a, b) -> int:
+ pass
diff --git a/testsuite/support.py b/testsuite/support.py
index cbe2f46..8241a92 100644
--- a/testsuite/support.py
+++ b/testsuite/support.py
@@ -168,6 +168,13 @@ def init_tests(pep8style):
def run_tests(filename):
"""Run all the tests from a file."""
+ # Skip tests meant for higher versions of python
+ ver_match = re.search(r'python(\d)(\d)?\.py$', filename)
+ if ver_match:
+ test_against_version = tuple(int(val or 0)
+ for val in ver_match.groups())
+ if sys.version_info < test_against_version:
+ return
lines = readlines(filename) + ['#:\n']
line_offset = 0
codes = ['Okay']