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
Say what kind of type an annotation is, and what it is made of. |
|
Field annotations of a pydantic model, see TypeShape.fields. |
|
Evaluate a forward reference. |
|
Field annotations of a TypedDict, with forward references resolved. |
Classes
The kind of a type, see classify. |
|
The shape of one annotation, see classify. |
|