Skip to content

False positive used-before-assignment with try/else/continue #6804

@mattclay

Description

@mattclay

Bug description

The used-before-assignment check reports a false positive with try/else/continue starting with pylint 2.13.0.

This issue is nearly identical to #6790, except it involves continue instead of return.

"""bug.py"""


def demo():
    """Demonstrate used-before-assignment regression in pylint==2.13.0 and 2.14.0."""
    for _temp in range(0, 1):
        try:
            pass
        except ValueError:
            error = True
        else:
            continue

        print(error)

Configuration

No response

Command used

pylint bug.py

Pylint output

************* Module bug
bug.py:14:14: E0601: Using variable 'error' before assignment (used-before-assignment)

Expected behavior

No errors reported, as was the case for 2.12.2.

Pylint version

pylint 2.14.0
astroid 2.11.5
Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
[GCC 9.3.0]

OS / Environment

Ubuntu 22.04.4

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 code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions