typing#
- class litestar.typing.FieldDefinition#
Bases:
object
Represents a function parameter or type annotation.
- args: tuple[Any, ...]#
The result of calling
get_args(annotation)
after unwrapping Annotated, e.g. (int,).
- instantiable_origin: Any#
An equivalent type to
origin
that can be safely instantiated. E.g.,Sequence
->list
.
- safe_generic_origin: Any#
An equivalent type to
origin
that can be safely used as a generic type across all supported Python versions.This is to serve safely rebuilding a generic outer type with different args at runtime.
- inner_types: tuple[litestar.typing.FieldDefinition, ...]#
The type’s generic args parsed as
FieldDefinition
, if applicable.
- kwarg_definition: KwargDefinition | DependencyKwarg | None#
Kwarg Parameter.
- property has_default: bool#
Check if the field has a default value.
- Returns:
True if the default is not Empty or Ellipsis otherwise False.
- property is_non_string_iterable: bool#
Check if the field type is an Iterable.
If
self.annotation
is an optional union, only the non-optional members of the union are evaluated.
- property is_non_string_sequence: bool#
Check if the field type is a non-string Sequence.
If
self.annotation
is an optional union, only the non-optional members of the union are evaluated.
- __init__(raw: Any, annotation: Any, type_wrappers: tuple[type, ...], origin: Any, args: tuple[Any, ...], metadata: tuple[Any, ...], instantiable_origin: Any, safe_generic_origin: Any, inner_types: tuple[litestar.typing.FieldDefinition, ...], default: Any, extra: dict[str, Any], kwarg_definition: KwargDefinition | DependencyKwarg | None, name: str) None #
- property is_non_string_collection: bool#
Whether the annotation is a non-string collection type or not.
- property bound_types: tuple[litestar.typing.FieldDefinition, ...] | None#
A tuple of bound types - if the annotation is a TypeVar with bound types, otherwise None.
- property generic_types: tuple[litestar.typing.FieldDefinition, ...] | None#
A tuple of generic types passed into the annotation - if its generic.
- property type_: Any#
The type of the annotation with all the wrappers removed, including the generic types.
- is_subclass_of(cl: type[Any] | tuple[type[Any], ...]) bool #
Whether the annotation is a subclass of the given type.
Where
self.annotation
is a union type, this method will returnTrue
when all members of the union are a subtype ofcl
, otherwise,False
.- Parameters:
cl¶ – The type to check, or tuple of types. Passed as 2nd argument to
issubclass()
.- Returns:
Whether the annotation is a subtype of the given type(s).
- has_inner_subclass_of(cl: type[Any] | tuple[type[Any], ...]) bool #
Whether any generic args are a subclass of the given type.
- Parameters:
cl¶ – The type to check, or tuple of types. Passed as 2nd argument to
issubclass()
.- Returns:
Whether any of the type’s generic args are a subclass of the given type.
- get_type_hints(*, include_extras: bool = False, resolve_generics: bool = False) dict[str, Any] #
Get the type hints for the annotation.
- classmethod from_annotation(annotation: Any, **kwargs: Any) FieldDefinition #
Initialize FieldDefinition.
- Parameters:
- Returns:
FieldDefinition
- classmethod from_kwarg(annotation: Any, name: str, default: Any = _EmptyEnum.EMPTY, inner_types: tuple[litestar.typing.FieldDefinition, ...] | None = None, kwarg_definition: KwargDefinition | DependencyKwarg | None = None, extra: dict[str, Any] | None = None) FieldDefinition #
Create a new FieldDefinition instance.