Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False-positive I0021: Useless suppression of 'line-too-long' (useless-suppression) #4212

Closed
bersbersbers opened this issue Mar 8, 2021 · 6 comments · Fixed by #5077
Closed
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@bersbersbers
Copy link

bersbersbers commented Mar 8, 2021

Steps to reproduce

Given a file a.py:

"""False-positive I0021: Useless suppression of 'line-too-long' (useless-suppression)"""
VAR = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"  # pylint:disable=line-too-long

Current behavior

Result of pylint --enable=useless-suppression a.py:

************* Module a
a.py:2:0: I0021: Useless suppression of 'line-too-long' (useless-suppression)

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

Expected behavior

No output.

pylint --version output

Result of pylint --version output:

pylint 2.7.2
astroid 2.5.1
Python 3.8.8 (default, Feb 22 2021, 14:04:38) 
[GCC 7.5.0]
@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Mar 8, 2021
@Pierre-Sassoulas
Copy link
Member

I can reproduce this, thank you.

@bersbersbers
Copy link
Author

Here's another example:

"""False-positive ungrouped-imports or useless-suppression."""
from re import sub

if 2 > 1:
    from pathlib import Path

    if 3 > 1:
        from re import match  # pylint:disable=ungrouped-imports


print(Path(), sub("", "", ""), match("", ""))

Assuming that ungrouped-imports, there is a false-positive useless-suppression. (Otherwise, there is a false-positive ungrouped-imports.)

@Pierre-Sassoulas
Copy link
Member

Hi @bersbersbers in your example the import are grouped each in their own scope (isort would not change the file) so there should not be an ungrouped-imports and the useles suppression is not a false positive.

@bersbersbers
Copy link
Author

Agreed. I found #2366 which is another false-positive of useless-suppression, but I also filed #4360 for the false-positive ungrouped-imports.

@Pierre-Sassoulas
Copy link
Member

Another example I just encountered in astroid:

************* Module astroid.node_classes
astroid/node_classes.py:864:0: I0021: Useless suppression of 'unused-variable' (useless-suppression)
        # pylint: disable=unused-variable; doesn't understand singledispatch
        @_repr_tree.register(NodeNG)
        def _repr_node(node, result, done, cur_indent="", depth=1):
            """Outputs a strings representation of an astroid node."""

If you remove the disable you then get astroid/node_classes.py:864:8: W0612: Unused variable '_repr_node' (unused-variable)

Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Apr 24, 2021
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Apr 24, 2021
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Sep 27, 2021
Also changes ``add_ignored_message()`` to make ``nodes`` parameter
optional.
Closes pylint-dev#4212
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Sep 27, 2021
Also changes ``add_ignored_message()`` to make ``nodes`` parameter
optional.
Closes pylint-dev#4212
@DanielNoord
Copy link
Collaborator

Another example I just encountered in astroid:

************* Module astroid.node_classes
astroid/node_classes.py:864:0: I0021: Useless suppression of 'unused-variable' (useless-suppression)
       # pylint: disable=unused-variable; doesn't understand singledispatch
       @_repr_tree.register(NodeNG)
       def _repr_node(node, result, done, cur_indent="", depth=1):
           """Outputs a strings representation of an astroid node."""

If you remove the disable you then get astroid/node_classes.py:864:8: W0612: Unused variable '_repr_node' (unused-variable)

This is a different issue and a different issue should be opened to track it. If you can give me a minimal working example to include in the tests I can work on fixing the false positive!

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.2 milestone Sep 27, 2021
Pierre-Sassoulas added a commit that referenced this issue Sep 28, 2021
Also changes ``add_ignored_message()`` to make ``nodes`` parameter
optional.
Closes #4212

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
3 participants