On this page
  1. typing.Annotated
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

typing.Annotated

Prev: typing.AbstractSet | Up: typing | Next: typing.Any
Rel: typing.AbstractSet, typing.Any, typing.assert_never, typing.assert_type
Ref: docs.python.org — typing.Annotated
Tags: #public #python3 #stdlib #typing


Import

import typing
from typing import Annotated

Signature & Overview

typing.Annotated(*args, **kwds)

Add context-specific metadata to a type.

Usage

from typing import Annotated, get_args, get_origin

PositiveInt = Annotated[int, "must be > 0"]
assert get_origin(PositiveInt) is Annotated
assert get_args(PositiveInt) == (int, "must be > 0")

Gotchas

REPL Inspect

from typing import Annotated
help(Annotated)

Linked from

Related notes