CKTIS / Python
Modul typing
Popisuje vztahy typů pomocí anotací, sjednocení, generik a protokolů a zpřístupňuje jejich metadata za běhu.
Verze: Python 3.14; repository image, production runtime not attested
Syntaxe
typing.get_type_hints(function, include_extras=True)Popisuje vztahy typů pomocí anotací, sjednocení, generik a protokolů a zpřístupňuje jejich metadata za běhu.
Python automaticky neověřuje anotovaná volání. Příklad načte metadata Annotated přes get_type_hints a get_args.
Bez include_extras zůstane pouze základní typ.
Pří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ýsledek
True ('tag',)
outside annotationBez include_extras zůstane pouze základní typ.