Skip to content

False negative unused-variable for catched exception when used in the inner context #4391

@Pierre-Sassoulas

Description

@Pierre-Sassoulas

Steps to reproduce

Given a file a.py:

#pylint: disable=missing-docstring

def function():
    unused = 1  # [unused-variable]
    try:
        1 / 0
    except ZeroDivisionError as error:  # [unused-variable]
        try:
            1 / 0
        except ZeroDivisionError as error:
            raise Exception("") from error

Current behavior

************* Module a
a.py:4:4: W0612: Unused variable 'unused' (unused-variable)

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

Expected behavior

************* Module a
a.py:4:4: W0612: Unused variable 'unused' (unused-variable)
a.py:8:30: W0612: Unused variable 'error' (unused-variable)

pylint --version output

pylint 2.7.4
astroid 2.5.3
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🪲False Negative 🦋No message is emitted but something is wrong with the codeHigh effort 🏋Difficult solution or problem to solve

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions