ruff/crates/red_knot_python_semantic/resources/mdtest/scopes/builtin.md
github-actions[bot] 53c7ef8bfe
Sync vendored typeshed stubs (#14977)
Co-authored-by: typeshedbot <>
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2024-12-15 01:02:41 +00:00

595 B

Builtin scope

Conditionally global or builtin

If a builtin name is conditionally defined as a global, a name lookup should union the builtin type with the conditionally-defined type:

def returns_bool() -> bool:
    return True

if returns_bool():
    chr = 1

def f():
    reveal_type(chr)  # revealed: Literal[chr] | Literal[1]

Conditionally global or builtin, with annotation

Same is true if the name is annotated:

def returns_bool() -> bool:
    return True

if returns_bool():
    chr: int = 1

def f():
    reveal_type(chr)  # revealed: Literal[chr] | int