[Python] Sub-attribute annotation syntax

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    It is possible to type the following code in Python3.12:

    class B:
    pass

    b = B()

    class A:
    a: "x"
    b.c: "y"


    Without b declaration, this code throws NameError. After that, A.__annotations__ shows: {'a': 'x'}. Annotation dicts of b and B are empty.

    Does this mean anything? Is it just some future syntax with no effects or does the b.c annotation end up somewhere?

    Continue reading...

Compartilhe esta Página