Skip to content

Commit

Permalink
Acknowledge that ellipses are allowed in typing annotations (#2236)
Browse files Browse the repository at this point in the history
Prevents false-positive bad-whitespace message
  • Loading branch information
brycepg authored and PCManticore committed Jul 2, 2018
1 parent 07aad49 commit 9c1812b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ Release date: |TBA|
Close #2022


* Fix false-positive ``bad-whitespace`` message for typing annoatations
with ellipses in them

Close 1992

What's New in Pylint 1.9?
=========================

Expand Down
3 changes: 3 additions & 0 deletions doc/whatsnew/2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,8 @@ Other Changes
this might actually cause bugs, so if you want to check for ``None`` values
as well, pass ``--ignore-none=n`` to pylint.

* Fix false-positive ``bad-whitespace`` message for typing annoatations
with ellipses in them


.. _PEP 563: https://www.python.org/dev/peps/pep-0563/
2 changes: 1 addition & 1 deletion pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def _has_valid_type_annotation(self, tokens, i):
elif token[1] == ',':
if not bracket_level:
return False
elif token[1] == '.':
elif token[1] in ('.', '...'):
continue
elif token[0] not in (tokenize.NAME, tokenize.STRING, tokenize.NL):
return False
Expand Down
7 changes: 7 additions & 0 deletions pylint/test/unittest_checker_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ def testOperatorSpacingBad(self):
args=('Exactly one', 'required', 'around', 'comparison', 'a< b\n ^'))):
self.checker.process_tokens(_tokenize_str('a< b\n'))

def testValidTypingAnnotationEllipses(self):
"""Make sure ellipses in function typing annotation
doesn't cause a false positive bad-whitespace message"""
with self.assertNoMessages():
self.checker.process_tokens(
_tokenize_str('def foo(t: Tuple[str, ...] = None):\n'))

def testEmptyLines(self):
self.checker.config.no_space_check = []
with self.assertAddsMessages(
Expand Down

0 comments on commit 9c1812b

Please sign in to comment.