Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

typing.Annotated

Associate ordered metadata with a base type for tools that recognize it.

Version: Python 3.14; repository image, production runtime not attested

Syntax

Annotated[T, metadata, ...]

Associate ordered metadata with a base type for tools that recognize it.

An unaware type checker treats the annotation as the base type. By default get_type_hints strips the extras, while include_extras=True preserves them.

The displayed limit is metadata and never checks the quantity by itself.

Examples

from typing import Annotated, get_args, get_type_hints

def quantity(value: Annotated[int, "limit=5", "units"]) -> int:
    return value

base = get_type_hints(quantity)["value"]
full = get_type_hints(quantity, include_extras=True)["value"]
print(base is int, get_args(full)[1:])
print(quantity(8))

Result

True ('limit=5', 'units')
8

The displayed limit is metadata and never checks the quantity by itself.

Sources