CKTIS / Python
Modul typing
Opisuje odnose tipova oznakama, unijama, generičkim tipovima i protokolima te daje pristup metapodacima pri izvršavanju.
Verzija: Python 3.14; repository image, production runtime not attested
Sintaksa
typing.get_type_hints(function, include_extras=True)Opisuje odnose tipova oznakama, unijama, generičkim tipovima i protokolima te daje pristup metapodacima pri izvršavanju.
Python ne provjerava automatski označene pozive. Primjer čita metapodatke Annotated s get_type_hints i get_args.
Bez include_extras ostaje samo osnovni tip.
Primjeri
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 annotationBez include_extras ostaje samo osnovni tip.