[Python] How to use a type defined later for function annotations?

Discussão em 'Python' iniciado por Stack, Fevereiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    The problem is like this:

    class A():
    def foo() -> B:
    pass

    class B():
    def bar() -> A:
    pass


    This will raise a NameError: name 'B' is not defined.

    For the sake of type checking, I'm not willing to change -> B to -> "B". Is there any workaround?

    Continue reading...

Compartilhe esta Página