Skip to content

Commit

Permalink
Support Ellipsis as a synonym for pass statements.
Browse files Browse the repository at this point in the history
Close #2718
  • Loading branch information
PCManticore committed Feb 4, 2019
1 parent 72fd895 commit c2af5c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ What's New in Pylint 2.3.0?

Release date: TBA

* Support ``Ellipsis`` as a synonym for ``pass`` statements.

Close #2718

* ``fixme`` gets triggered only on comments.

Close #2321
Expand Down
14 changes: 9 additions & 5 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ def report_by_type_stats(sect, stats, old_stats):
if total != 0:
try:
documented = total - stats["undocumented_" + node_type]
percent = (documented * 100.) / total
percent = (documented * 100.0) / total
nice_stats[node_type]["percent_documented"] = "%.2f" % percent
except KeyError:
nice_stats[node_type]["percent_documented"] = "NC"
try:
percent = (stats["badname_" + node_type] * 100.) / total
percent = (stats["badname_" + node_type] * 100.0) / total
nice_stats[node_type]["percent_badname"] = "%.2f" % percent
except KeyError:
nice_stats[node_type]["percent_badname"] = "NC"
Expand Down Expand Up @@ -1089,13 +1089,17 @@ def visit_expr(self, node):
return
self.add_message("pointless-string-statement", node=node)
return
# ignore if this is :

# Ignore if this is :
# * a direct function call
# * the unique child of a try/except body
# * a yield (which are wrapped by a discard node in _ast XXX)
# * a yieldd statement
# * an ellipsis (which can be used on Python 3 instead of pass)
# warn W0106 if we have any underlying function call (we can't predict
# side effects), else pointless-statement
if isinstance(expr, (astroid.Yield, astroid.Await, astroid.Call)) or (
if isinstance(
expr, (astroid.Yield, astroid.Await, astroid.Ellipsis, astroid.Call)
) or (
isinstance(node.parent, astroid.TryExcept) and node.parent.body == [node]
):
return
Expand Down
10 changes: 10 additions & 0 deletions pylint/test/functional/statement_without_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,13 @@ def test(self):
self.val = 42
# +1:[pointless-string-statement]
""" this is an invalid attribute docstring. """


def ellipsis():
"""Test that an Ellipsis as a body does not trigger the error"""
...


class EllipsisBody:
"""Test that an Ellipsis as a body does not trigger the error"""
...

0 comments on commit c2af5c7

Please sign in to comment.