Skip to content

Commit

Permalink
pylint is less eager to consume the whole line for pragmas
Browse files Browse the repository at this point in the history
The regex was adapted so that we either stop at one of `;` or `#`, or at the end
of the line. This should improve the situation a little bit when dealing with the
flags of other linters.

Close #2485
  • Loading branch information
PCManticore committed Sep 29, 2018
1 parent 5d066ed commit daef49a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 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.2?

Release date: TBA

* ``pylint`` is less eager to consume the whole line for pragmas

Close #2485

* Change ``unbalanced-tuple-unpacking`` back to a warning.

It used to be a warning until a couple of years ago, after it was promoted to
Expand Down
19 changes: 19 additions & 0 deletions pylint/test/functional/control_pragmas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# pylint: disable=missing-docstring


def test_pragma():
"""Test that the control pragmas are not too eager to consume the entire line
We should stop either at:
- ; or #
- or at the end of line
"""
# noqa: E501 # pylint: disable=unused-variable #nosec
variable = 1

# noqa # pylint: disable=undefined-variable,no-member; don't trigger
other_variable = some_variable + variable.member

# noqa # pylint: disable=unbalanced-tuple-unpacking,no-member # no trigger
first, second = some_other_variable
return first + other_variable.method()
Empty file.
4 changes: 2 additions & 2 deletions pylint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
MSG_STATE_SCOPE_MODULE = 1
MSG_STATE_CONFIDENCE = 2

# Allow stopping after the first semicolon encountered,
# Allow stopping after the first semicolon/hash encountered,
# so that an option can be continued with the reasons
# why it is active or disabled.
OPTION_RGX = re.compile(r"\s*#.*\bpylint:\s*([^;]+);{0,1}")
OPTION_RGX = re.compile(r"\s*#.*\bpylint:\s*([^;#]+)[;#]{0,1}")

# The line/node distinction does not apply to fatal errors and reports.
_SCOPE_EXEMPT = "FR"
Expand Down

0 comments on commit daef49a

Please sign in to comment.