Skip to content

False positive: unused-variable + undefined-variable when using := operator in stacked decorators #9641

Open

Description

Bug description

"""The following code should lint ok, but pylint issues undefined- / unused-variable l"""
import pytest


@pytest.mark.parametrize("x", l := [1, 2, 3])
@pytest.mark.parametrize("y", l)
def test_demo(x, y):
    """pylint demo"""
    _ = [x, y]

Configuration

No response

Command used

pylint test_pylint.py

Pylint output

************* Module test.configdb.config_utils.test_pylint
test_pylint.py:6:30: E0602: Undefined variable 'l' (undefined-variable)
test_pylint.py:5:30: W0612: Unused variable 'l' (unused-variable)

Expected behavior

linting should be ok

Pylint version

$ pylint --version
pylint 3.2.0
astroid 3.2.1
Python 3.10.13 (main, Jan 12 2024, 16:58:07) [GCC 11.4.0]

OS / Environment

Ubuntu 22.04.4 LTS

Additional dependencies

pytest==7.1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C: undefined-variableIssues related to 'undefined-variable' checkC: used-before-assignmentIssues related to 'used-before-assignment' checkDecoratorsFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions