Herramientas de usuario

Herramientas del sitio


wiki2:python:typing

¡Esta es una revisión vieja del documento!


Python Typing

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
wiki2/python/typing.1647279753.txt.gz · Última modificación: 2022/03/14 18:42 (editor externo)