ruff/crates/red_knot_python_semantic/resources/mdtest/expression/attribute.md
InSync 15fe540251
Improve mdtests style (#14884)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2024-12-10 13:05:51 +00:00

681 B

Attribute access

Boundness

def _(flag: bool):
    class A:
        always_bound = 1

        if flag:
            union = 1
        else:
            union = "abc"

        if flag:
            possibly_unbound = "abc"

    reveal_type(A.always_bound)  # revealed: Literal[1]

    reveal_type(A.union)  # revealed: Literal[1] | Literal["abc"]

    # error: [possibly-unbound-attribute] "Attribute `possibly_unbound` on type `Literal[A]` is possibly unbound"
    reveal_type(A.possibly_unbound)  # revealed: Literal["abc"]

    # error: [unresolved-attribute] "Type `Literal[A]` has no attribute `non_existent`"
    reveal_type(A.non_existent)  # revealed: Unknown