CKTIS / Python
Module typing
Beschrijft typeverbanden met annotaties, unies, generieken en protocollen en ontsluit hun metagegevens tijdens uitvoering.
Versie: Python 3.14; repository image, production runtime not attested
Syntax
typing.get_type_hints(function, include_extras=True)Beschrijft typeverbanden met annotaties, unies, generieken en protocollen en ontsluit hun metagegevens tijdens uitvoering.
Python controleert geannoteerde aanroepen niet automatisch. Het voorbeeld leest Annotated-metagegevens met get_type_hints en get_args.
Zonder include_extras blijft alleen het basistype over.
Voorbeelden
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"))
Resultaat
True ('tag',)
outside annotationZonder include_extras blijft alleen het basistype over.