typing_validation.nodes
The node model: one interned node per distinct type, holding the type it was built from, its form, its interned children, and its memoised properties.
Everything except validate is built on this one
class. It is simultaneously the unit of interning, the thing
inspect_type reports, and the thing that explains a
failure. It can be all of those at once precisely because none of them is on a
hot path — which is also why this module may share freely with them, and why it
shares nothing with the interpreter.
TypeForm
- final class TypeForm(*values)[source]
Bases:
EnumWhat kind of type a node is, mirroring the catalogue in
TYPES.md.- ALIAS = 'alias'
A PEP 695 type alias, and the point at which a recursive type closes.
- ANY_NAMED_TUPLE = 'any NamedTuple'
Bare
typing.NamedTuple: any named tuple instance.
- CLASS = 'class'
A plain class or abstract base class, checked with
isinstance.
- COLLECTION = 'collection'
A collection whose every item is checked against one type argument.
- GENERIC_CLASS = 'generic class'
A parametrised class whose arguments cannot be checked, by design.
- ITERATOR = 'iterator'
An iterator, whose items cannot be checked without consuming it.
- MAPPING = 'mapping'
A mapping whose keys and values are each checked against an argument.
- MAYBE_ITEMS = 'iterable or container'
An iterable or container, whose items are checked only when the value is also a
Collection.
- NAMED_TUPLE = 'NamedTuple'
A concrete named tuple class, whose children are its field types.
- NONE = 'None'
Noneandtypes.NoneType.
- PLUGIN = 'plugin'
A parametrised class whose arguments a plugin knows how to check.
- PROTOCOL = 'protocol'
A runtime-checkable protocol.
- TUPLE = 'tuple'
A fixed-length, variadic or empty tuple.
- TYPE_OF = 'type of'
Type[T]andtype[T].
- TYPE_VAR = 'type variable'
A type variable, checked against its bound or its constraints.
- UNION = 'union'
A union: valid if at least one member is.
- UNSUPPORTED = 'unsupported'
A type we cannot validate against. Poisons whatever contains it.
TypeNode
- final class TypeNode(t, /)[source]
Bases:
objectOne distinct type, analysed.
Nodes are interned on the type itself, so
list[int]is analysed once and shared everywhere it occurs. Interning is never semantically observable: a cold, cleared or bypassed cache changes cost and nothing else. That is what lets an unhashable type simply skip the cache, and what makes eviction safe to expose at all.- property supported
Whether this type, and every component of it, can be validated against.
Support is all-or-nothing: one unsupported component poisons the whole type, transitively.
- Return type: