CKTIS / Python
typing.Annotated
Associa metadados ordenados a um tipo de base.
Versão: Python 3.14; repository image, production runtime not attested
Sintaxe
Annotated[T, metadata, ...]Associa metadados ordenados a um tipo de base.
Um verificador que os desconheça usa o tipo de base. A função get_type_hints remove os extras por predefinição e conserva-os com include_extras=True.
A etiqueta de limite não valida o valor 8.
Exemplos
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')
8A etiqueta de limite não valida o valor 8.