CKTIS / Python
typing.Annotated
Adjunta metadatos ordenados a un tipo base.
Versión: Python 3.14; repository image, production runtime not attested
Sintaxis
Annotated[T, metadata, ...]Adjunta metadatos ordenados a un tipo base.
Un comprobador que los desconoce utiliza el tipo base. La función get_type_hints descarta los extras por defecto y los conserva con include_extras=True.
La etiqueta de límite no valida el valor 8.
Ejemplos
from typing import Annotated, get_args, get_type_hints
def quantity(value: Annotated[int, "limit=5", "units"]) -> int:
return value
base = get_type_hints(quantity)["value"]
full = get_type_hints(quantity, include_extras=True)["value"]
print(base is int, get_args(full)[1:])
print(quantity(8))
Resultado
True ('limit=5', 'units')
8La etiqueta de límite no valida el valor 8.