Skip to content

E0601 false positive when nested try block exhaustively defines name, raises, or returns #7350

Open
@AndersMunch

Description

@AndersMunch

Bug description

This produces a using 'x' before assignment error:

"""pylint_false_positive.py"""
def test():
    try:
        try:
            x = None
        except:
            x = None
            raise
    finally:
        print("x", x)

Configuration

No response

Command used

pylint -E pylint_false_positive.py

Pylint output

************* Module pylint_false_positive
pylint_false_positive.py:10: [E0601(used-before-assignment), test] Using variable 'x' before assignment

Expected behavior

Expected no error, x is assigned in all branches.

Pylint version

pylint 2.14.5
astroid 2.11.7
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: used-before-assignmentIssues related to 'used-before-assignment' checkControl flowRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeMinor 💅Polishing pylint is always nice

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions