Skip to content

Python 3 UnboundLocalError not detected when variable referenced after shadowed by exception variable #345

@jayvdb

Description

@jayvdb

For

def a():
    e = 1
    try:
        raise RuntimeError('forced error')
    except Exception as e:
        print(e)
    print(e)

a()

In both Python 2 and 3, exception variable e shadows the local variable e, and is not being reported.

In python3, e is unbound after the exception block, and a UnboundLocalError occurs when the local variable e is referenced because it was disappeared.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions