CKTIS / Python
Modul typing
Opisuje vzťahy typov pomocou anotácií, zjednotení, generík a protokolov a sprístupňuje ich metadáta za behu.
Verzia: Python 3.14; repository image, production runtime not attested
Syntax
typing.get_type_hints(function, include_extras=True)Opisuje vzťahy typov pomocou anotácií, zjednotení, generík a protokolov a sprístupňuje ich metadáta za behu.
Python automaticky neoveruje anotované volania. Príklad načíta metadáta Annotated cez get_type_hints a get_args.
Bez include_extras zostane iba základný typ.
Príklady
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"))
Výsledok
True ('tag',)
outside annotationBez include_extras zostane iba základný typ.