Pylint: Regression on `# pylint: disable` comment

Created on 16 Jul 2018  路  9Comments  路  Source: PyCQA/pylint

Steps to reproduce

$ pip list | egrep "pylint|astroid"
astroid                  2.0       
pylint                   2.0.0
$ cat fail.py 
import os  # foobar # pylint: disable=unused-import
$ pylint --disable all --enable unused-import fail.py 
************* Module fail
fail.py:1:0: W0611: Unused import os (unused-import)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

while

$ pip show pylint astroid | grep Version
Version: 1.9.2
Version: 1.6.5
$ cat fail.py 
import os  # foobar # pylint: disable=unused-import
$ pylint --disable all --enable unused-import fail.py 
No config file found, using default configuration

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 0.00/10, +10.00)
bug

Most helpful comment

My solution was to remove the second "#" comment indicator, which was there only due to formatting.

Unfortunately, this is not possible if the other comment is there to disable mypy checks because it currently only works if it is the first comment block.

Ex:

line to ignore  # type: ignore # pylint: disable=check-to-ignore

This used to work. Now, the two cannot be combined on the same line.

All 9 comments

I can confirm the same bug, in fact I meant to report his just now. My solution was to remove the second "#" comment indicator, which was there only due to formatting.

My solution was to remove the second "#" comment indicator, which was there only due to formatting.

Unfortunately, this is not possible if the other comment is there to disable mypy checks because it currently only works if it is the first comment block.

Ex:

line to ignore  # type: ignore # pylint: disable=check-to-ignore

This used to work. Now, the two cannot be combined on the same line.

I can also confirm this bug, thanks for raising it! It seems it was introduced by https://github.com/PyCQA/pylint/pull/1743.

Confirmed here as well.

I can add my voice to the growing chorus:

    def run_TheCode_and_report_it(self):
        """A helper for the next few tests."""
        cov = coverage.Coverage()
        cov.start()
        import TheCode  # pragma: nested # pylint: disable=import-error, unused-variable
        cov.stop()      # pragma: nested
        return self.get_report(cov)

With Pylint 1.9.2, I get no warnings. With 2.1.1, I get:

tests/test_summary.py:598: Unable to import 'TheCode' (import-error)
tests/test_summary.py:598: Unused variable 'TheCode' (unused-variable)

Hey folks, this should be fixed in the master branch, please give it a go and let me know if it works for you!

This still seems to be a problem, though it's shifted a bit. This file:

"""A pylint problem"""

def something():
    """A helper for the next few tests."""
    import TheCode  # pragma: nested # pylint: disable=import-error, unused-variable

with no pylintrc produces:

************* Module pylint_2297
pylint_2297.py:5:4: W0611: Unused import TheCode (unused-import)

------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 0.00/10, +5.00)

@nedbat Notice the disable uses unused-variable while the emitted error is unused-import. This changed recently as it didn't make sense for pylint to emit unused-variable for imports.

oops! my mistake :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DGalt picture DGalt  路  3Comments

mrginglymus picture mrginglymus  路  3Comments

glmdgrielson picture glmdgrielson  路  3Comments

z4y4ts picture z4y4ts  路  3Comments

thanatos picture thanatos  路  3Comments