emmet.core.types.introspection

Shape-level introspection of type annotations.

classify looks at a single annotation and reports what kind of type it is (sequence, mapping, union, model, …) and what its immediate components are, without recursing. Consumers decide what to do with each kind and recurse themselves via TypeShape.child, which keeps track of the namespace needed to resolve forward references.

This is the one place where emmet knows how to take apart the annotations used across its models (Optional, NotRequired, TypeVar`s, `TypedDict`s, pydantic models with `type_overrides, MSONable type adapters, …). It is shared by:

  • emmet.core.arrow.arrowize, which folds a type into a pyarrow schema

  • emmet.core.types.id_paths.find_identifier_paths, which collects the location of identifier fields in a document

This module must not import pyarrow, as it is used where pyarrow is not installed.

Functions

classify

Say what kind of type an annotation is, and what it is made of.

model_fields

Field annotations of a pydantic model, see TypeShape.fields.

resolve_forward_ref

Evaluate a forward reference.

typeddict_fields

Field annotations of a TypedDict, with forward references resolved.

Classes

Kind

The kind of a type, see classify.

TypeShape

The shape of one annotation, see classify.

wrapper