Skip to content

False positive used-before-assignment when else of try/else calls sys.exit() #7563

Closed
@kayhayen

Description

@kayhayen

Bug description

Given this code snippet:

    try:
        yamllint.cli.run([document])
    except SystemExit as e:
        lint_result = e.code
    else:
        sys.exit("Error, yamllint didn't raise expected SystemExit exception.")
    if lint_result != 0:
        sys.exit("Error, no lint clean yaml.")

    my_print("OK.", style="blue")

Since sys.exit() in the else branch is aborting, there is no doubt that lint_result must be assigned.

Configuration

No configuration

Command used

pylint m.py

Pylint output

Warning used-before-assignment for the `lint_result` usage.

Expected behavior

Warning should not be given.

Pylint version

pylint 2.15.3
astroid 2.12.10
Python 3.9.2 (default, Feb 28 2021, 17:03:44)

OS / Environment

Debian Buster with PyPI packages

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 codeGood first issueFriendly and approachable by new contributorsNeeds 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