Skip to content

Block-level disabling of invalid-name does not work after else #3898

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

Closed
bersbersbers opened this issue Oct 13, 2020 · 5 comments
Closed

Block-level disabling of invalid-name does not work after else #3898

bersbersbers opened this issue Oct 13, 2020 · 5 comments
Labels
Bug 🪲 Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code Minor 💅 Polishing pylint is always nice

Comments

@bersbersbers
Copy link

bersbersbers commented Oct 13, 2020

Steps to reproduce

bug.py:

"""Bug."""
if 0 == 1:
    pass
else:
    # pylint:disable=invalid-name
    data_id = 1

Current behavior

~> pylint bug.py --enable=useless-suppression
************* Module bug
bug.py:6:4: C0103: Constant name "data_id" doesn't conform to UPPER_CASE naming style (invalid-name)
bug.py:5:0: I0021: Useless suppression of 'invalid-name' (useless-suppression)

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

Expected behavior

No warning.

pylint --version output

~> pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.8.6 (default, Sep 29 2020, 15:36:55)
[GCC 7.5.0]

This may be a duplicate of #3136 (or not).

@hippo91
Copy link
Contributor

hippo91 commented Oct 17, 2020

@bersbersbers thanks for your report. I can reproduce it.

@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels Oct 17, 2020
@hippo91
Copy link
Contributor

hippo91 commented Oct 17, 2020

@bersbersbers note that if you put the pylint pragma at the end of line instead above it, then the message go away.

@hippo91 hippo91 added the Minor 💅 Polishing pylint is always nice label Oct 17, 2020
@nmarrow
Copy link
Contributor

nmarrow commented Jan 6, 2021

I think the issue ultimately comes from astroid. From what I can tell, the disable pragmas are assigned to line ranges based on the associated node's block_range (in file_state.py). In this case the node is an If but the line number corresponds to the orelse portion; the orelse attribute of the If node is just a list of the expressions in the block. Since the pylint comment comes before those expressions, _elsed_block_range ends returning a range for the orelse block that doesn't actually include the expressions in it (since the only way to determine the line range of the orelse is to take the start of the first expression and the end of the last)

@hippo91
Copy link
Contributor

hippo91 commented Jan 23, 2021

@nmarrow thanks for your investigations.

@Pierre-Sassoulas
Copy link
Member

Duplicate of #872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code Minor 💅 Polishing pylint is always nice
Projects
None yet
Development

No branches or pull requests

4 participants