ruff/crates/red_knot_python_semantic/resources/mdtest/assignment/unbound.md
Micha Reiser 6aaf1d9446
[red-knot] Remove lint-phase (#13922)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-10-25 18:40:52 +00:00

524 B

Unbound

Unbound

x = foo  # error: [unresolved-reference] "Name `foo` used when not defined"
foo = 1

# error: [unresolved-reference]
# revealed: Unbound
reveal_type(x)

Unbound class variable

Name lookups within a class scope fall back to globals, but lookups of class attributes don't.

def bool_instance() -> bool:
    return True

flag = bool_instance()
x = 1

class C:
    y = x
    if flag:
        x = 2

reveal_type(C.x)  # revealed: Literal[2]
reveal_type(C.y)  # revealed: Literal[1]