pylint
pylint copied to clipboard
line-too-long false positive on long comment in function with disable=line-too-long if comment is after all statements
Bug description
# pylint: disable=missing-module-docstring,missing-class-docstring,too-few-public-methods
def func1():
# pylint: disable=line-too-long
print('looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong statement')
# pylint doesn't like this long comment if it's after all this function's statements, but it's fine if there are no more statements in the module after this function
# pylint: enable=line-too-long
print()
Configuration
No response
Command used
pylint --persistent=n a.py
Pylint output
************* Module a
a.py:6:0: C0301: Line too long (169/100) (line-too-long)
-----------------------------------
Your code has been rated at 6.67/10
Expected behavior
I expect line 6 (the long comment) to be ignored since line-too-long is disabled for that function. I suspect the comment is not considered to be "part" of the function regardless of its indentation since it appears after the function's final statement, and that line-too-long becomes re-enabled upon the first statement following the function definition which would explain why it works fine when I remove the print() following the function, but pylint should handle this properly because from my perspective the comment is a part of the function since it's indented to be within it.
BTW it makes no difference whether the enable=line-too-long comment is there or not, I just left it in to emphasize how wrong this behavior appears to a user.
Pylint version
pylint 3.2.2
astroid 3.2.2
Python 3.12.2 (main, Mar 25 2024, 02:44:33) [GCC 12.3.1 20230526]
OS / Environment
Gentoo Linux, with profile default/linux/amd64/17.1/desktop/plasma. However I ran this inside a venv, in which I only installed pylint.
Additional dependencies
No response