typing_validation.inspector

Type inspector object, passed to can_validate to determine whether a type can be validated (and record detailed type information).

TypeInspector

class TypeInspector[source]

Bases: object

Class used to record the structure of a type during a call to can_validate.

__repr__()[source]

Representation of the inspector, including the type_structure.

Return type:

str

property recorded_type

The type recorded by this type inspector during validation.

Return type:

Any

property type_annotation

The type annotation for the recorded type. Differs from the output of type_structure in the following ways:

  1. The annotation is on a single line.

  2. Unsupported types are not wrapped.

Return type:

str

property type_structure

The structure of the recorded type:

  1. The string spans multiple lines, with indentation levels matching the nesting level of inner types.

  2. Any unsupported types encountered are wrapped using the generic type UnsupportedType.

Return type:

str

property unsupported_types

The sequence of unsupported types encountered during validation.

Return type:

typing.Tuple[Any, …]

UnsupportedType

class UnsupportedType[source]

Bases: type

Wrapper for an unsupported type encountered by a TypeInspector instance during validation.

property wrapped_type

The underlying type.

Return type:

Any