CKTIS / Python
typing.Annotated
Osnovnemu tipu pripne urejene metapodatke.
Različica: Python 3.14; repository image, production runtime not attested
Sintaksa
Annotated[T, metadata, ...]Osnovnemu tipu pripne urejene metapodatke.
Preverjevalnik brez njihove podpore upošteva osnovni tip. Funkcija get_type_hints dodatke privzeto odstrani, z include_extras=True pa jih ohrani.
Oznaka meje ne preveri vrednosti 8.
Primeri
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))
Rezultat
True ('limit=5', 'units')
8Oznaka meje ne preveri vrednosti 8.