pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.33k stars 1.14k forks source link

Per-file enable does not work for C (convention) messages #3436

Open martimlobao opened 4 years ago

martimlobao commented 4 years ago

Steps to reproduce

  1. Create .pylintrc file:
    [MASTER]
    disable=C,
        W
  2. Create test.py file:
    
    # pylint: enable=C,W

import json

def test(foo = "bar"): return foo

3. Run `pylint test.py`

### Current behavior
Warnings (`W`) are re-enabled in `test.py` but not conventions (`C`):

$ pylint test.py ***** Module test test.py:3:0: W0611: Unused import json (unused-import)


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


### Expected behavior
Conventions (`C`) should also be re-enabled:

$ pylint test.py ***** Module test test.py:5:13: C0326: No space allowed around keyword argument assignment def test(foo = "bar"): ^ (bad-whitespace) test.py:1:0: C0111: Missing module docstring (missing-docstring) test.py:5:0: C0102: Black listed name "foo" (blacklisted-name) test.py:5:0: C0111: Missing function docstring (missing-docstring) test.py:3:0: W0611: Unused import json (unused-import)


Your code has been rated at -6.67/10 (previous run: 6.67/10, -13.33)


### pylint --version output

$ pylint --version pylint 2.4.4 astroid 2.3.3 Python 3.7.4 (default, Jul 25 2019, 00:08:15) [Clang 11.0.0 (clang-1100.0.20.17)]

PCManticore commented 4 years ago

I can confirm the bug, thanks for reporting.

martimlobao commented 4 years ago

If the fix isn't too complicated, I'd be happy to have a go. I just need some general direction of where to look.

analog-cbarber commented 4 years ago

I am seeing the same thing for specific docstring checks that were disabled in the .pylintrc file (using 2.5.3). I assume this is the same issue:

# pylint: enable=missing-docstring
clavedeluna commented 1 year ago

Can still reproduce this today.

DanielNoord commented 1 year ago

This requires a complete overhaul of the way we enable and disable messages. The issue is that we disable certain checkers and methods based on whether they are going to be called. In this specific example we disable the complete DocstringChecker and all of its methods as the messages the checker emits are all disabled.

Changing this part of the code to be context aware would require a major overhaul and might nog even be feasible.