Skip to content

disable-next leaks into the whole block if it's followed by an empty line #7401

Closed
@Jackenmen

Description

@Jackenmen

Bug description

  1. Create a virtual environment (e.g. run virtualenv pylint-repro)
  2. Activate the virtual environment (e.g. run . pylint-repro/bin/activate
  3. Install pylint (e.g. pip install pylint)
  4. Put these contents into an example.py file:
# pylint: disable=missing-docstring


def func():
    # pylint: disable-next=unused-variable

    test = 43
    blah = 123
  1. Run pylint example.py
  2. See the issue.

Configuration

No response

Command used

pylint example.py

Pylint output

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

Expected behavior

I expected the second unused variable to be reported, as is the case when not putting an empty line between disable-next and the line I'm suppressing errors for:

# pylint: disable=missing-docstring


def func():
    # pylint: disable-next=unused-variable
    test = 43
    blah = 123

Example output:

************* Module example
example.py:7:4: W0612: Unused variable 'blah' (unused-variable)

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

It probably would also be fine if an empty line between the comment and line to suppress simply didn't work. My issue is that this appears to do what I've intended - it suppresses the unused variable for next line - but it also does things it wasn't supposed to.

Pylint version

pylint 2.15.0
astroid 2.12.5
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]

OS / Environment

Ubuntu 22.04.1, Python 3.10 shipped with the system

Additional dependencies

No response

Metadata

Metadata

Assignees

Labels

Bug 🪲C: Pragma'sNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions