¡Esta es una revisión vieja del documento!
Devolver el tipo de la misma clase:
from typing import Self
class Foo:
def returns_self(self) -> Self:
return self
Alias de tipo:
from typing import TypeAlias Factors: TypeAlias = list[int]
Definición de un tipo (en este caso self):
from typing import TypeVar
Self = TypeVar("Self", bound="Foo")
class Foo:
def returns_self(self: Self) -> Self:
return self