CKTIS / Python
Modul typing
Opiše razmerja med tipi z oznakami, unijami, generičnimi tipi in protokoli ter omogoča pregled metapodatkov med izvajanjem.
Različica: Python 3.14; repository image, production runtime not attested
Sintaksa
typing.get_type_hints(function, include_extras=True)Opiše razmerja med tipi z oznakami, unijami, generičnimi tipi in protokoli ter omogoča pregled metapodatkov med izvajanjem.
Python samodejno ne preverja označenih klicev. Primer prebere metapodatke Annotated z get_type_hints in get_args.
Brez include_extras ostane le osnovni tip.
Primeri
import typing
def identify(code: typing.Annotated[int, "tag"]) -> int:
return code
base = typing.get_type_hints(identify)["code"]
full = typing.get_type_hints(identify, include_extras=True)["code"]
print(base is int, typing.get_args(full)[1:])
print(identify("outside annotation"))
Rezultat
True ('tag',)
outside annotationBrez include_extras ostane le osnovni tip.