Skip to content

Commit bd17ca6

Browse files
Tadaboodysigmavirus24
authored andcommitted
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 * 🐛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
1 parent c507b72 commit bd17ca6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

pycodestyle.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
115115
UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
116116
ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-'])
117117
WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])
118+
# Warn for -> function annotation operator in py3.5+ (issue 803)
119+
FUNCTION_RETURN_ANNOTATION_OP = ['->'] if sys.version_info >= (3, 5) else []
118120
WS_NEEDED_OPERATORS = frozenset([
119121
'**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
120-
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='])
122+
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='] +
123+
FUNCTION_RETURN_ANNOTATION_OP)
121124
WHITESPACE = frozenset(' \t')
122125
NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
123126
SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT])

testsuite/python35.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#: E225
2+
def bar(a, b)->int:
3+
pass
4+
#: Okay
5+
def baz(a, b) -> int:
6+
pass

testsuite/support.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ def init_tests(pep8style):
168168

169169
def run_tests(filename):
170170
"""Run all the tests from a file."""
171+
# Skip tests meant for higher versions of python
172+
ver_match = re.search(r'python(\d)(\d)?\.py$', filename)
173+
if ver_match:
174+
test_against_version = tuple(int(val or 0)
175+
for val in ver_match.groups())
176+
if sys.version_info < test_against_version:
177+
return
171178
lines = readlines(filename) + ['#:\n']
172179
line_offset = 0
173180
codes = ['Okay']

0 commit comments

Comments
 (0)