TypeTypedDict
Auto-generated documentation for mypy_boto3_builder.type_annotations.type_typed_dict module.
Wrapper for typing/typing_extensions.TypedDict
type annotations.
- mypy-boto3-builder / Modules / Mypy Boto3 Builder / Type Annotations / TypeTypedDict
- TypeTypedDict
- TypeTypedDict().add_attribute
- TypeTypedDict().copy
- TypeTypedDict().get_attribute
- TypeTypedDict().get_children_literals
- TypeTypedDict().get_children_typed_dicts
- TypeTypedDict().get_children_types
- TypeTypedDict().get_import_record
- TypeTypedDict().get_local_types
- TypeTypedDict().get_optional
- TypeTypedDict().get_required
- TypeTypedDict().get_sort_key
- TypeTypedDict.get_typing_import_record
- TypeTypedDict().has_both
- TypeTypedDict().has_optional
- TypeTypedDict().has_required
- TypeTypedDict().is_dict
- TypeTypedDict().is_same
- TypeTypedDict().is_stringified
- TypeTypedDict().is_typed_dict
- TypeTypedDict().iterate_children
- TypeTypedDict().render
- TypeTypedDict().replace_self_references
- TypeTypedDict().requires_safe_render
- TypeTypedDict().stringify
- TypeTypedDict().type_hint_annotations
- TypedDictAttribute
- TypeTypedDict
TypeTypedDict
class TypeTypedDict(FakeAnnotation):
def __init__(
name: str,
children: Iterable[TypedDictAttribute] = (),
docstring: str = '',
stringify: bool = False,
replace_with_dict: Iterable[str] = tuple(),
) -> None:
Wrapper for typing/typing_extensions.TypedDict
type annotations.
Arguments
name
- Type name.children
- Typed dict attributes.docstring
- Docstring for render.stringify
- Convert type annotation to string to avoid circular deps.replace_with_dict
- Render Dict[str, Any] instead to avoid circular dependencies.
See also
TypeTypedDict().add_attribute
def add_attribute(
name: str,
type_annotation: FakeAnnotation,
required: bool,
) -> None:
Add new attribute to a dictionary.
Arguments
name
- Argument name.type_annotation
- Argument type annotation.required
- Whether argument has to be set.
See also
TypeTypedDict().copy
def copy() -> 'TypeTypedDict':
Create a copy of type annotation wrapper.
TypeTypedDict().get_attribute
def get_attribute(name: str) -> TypedDictAttribute:
Find attribute by name
.
Arguments
name
- Attribute name.
Returns
Found attribute.
See also
TypeTypedDict().get_children_literals
def get_children_literals(
processed: Iterable['TypeTypedDict'] = tuple(),
) -> set[TypeLiteral]:
Extract required TypeLiteral list from attributes.
See also
TypeTypedDict().get_children_typed_dicts
def get_children_typed_dicts() -> set['TypeTypedDict']:
Extract required TypeTypedDict list from attributes.
TypeTypedDict().get_children_types
def get_children_types() -> set[FakeAnnotation]:
Extract required type annotations from attributes.
See also
TypeTypedDict().get_import_record
def get_import_record() -> ImportRecord:
Get import record required for using type annotation.
See also
TypeTypedDict().get_local_types
def get_local_types() -> list[FakeAnnotation]:
Get internal types generated by builder.
See also
TypeTypedDict().get_optional
def get_optional() -> list[TypedDictAttribute]:
Get a list of optional attributes.
See also
TypeTypedDict().get_required
def get_required() -> list[TypedDictAttribute]:
Get a list of required attributes.
See also
TypeTypedDict().get_sort_key
def get_sort_key() -> str:
Sort Typed Dicts by name.
TypeTypedDict.get_typing_import_record
@staticmethod
def get_typing_import_record() -> ImportRecord:
Get import record required for using TypedDict.
Fallback to typing_extensions for py38-.
See also
TypeTypedDict().has_both
def has_both() -> bool:
Whether TypedDict has both optional and required keys.
TypeTypedDict().has_optional
def has_optional() -> bool:
Whether TypedDict has optional keys.
TypeTypedDict().has_required
def has_required() -> bool:
Whether TypedDict has required keys.
TypeTypedDict().is_dict
def is_dict() -> bool:
Always True as it is a TypedDict.
TypeTypedDict().is_same
def is_same(other: 'TypeTypedDict') -> bool:
Check whether typed dict attributes are the same as other
.
TypeTypedDict().is_stringified
def is_stringified() -> bool:
Whether TypedDict usage should be rendered as a string.
TypeTypedDict().is_typed_dict
def is_typed_dict() -> bool:
Always True as it is a TypedDict.
TypeTypedDict().iterate_children
def iterate_children() -> Iterator[TypedDictAttribute]:
Iterate over children from required to optional.
See also
TypeTypedDict().render
def render(parent_name: str = '') -> str:
Render type annotation to a valid Python code for local usage.
Returns
A string with a valid type annotation.
TypeTypedDict().replace_self_references
def replace_self_references() -> None:
Replace self refenrences with Dict[str, Any]
to avoid circular dependencies.
TypeTypedDict().requires_safe_render
@property
def requires_safe_render() -> bool:
Whether TypedDict has reserved words and has to be rendered safely.
TypeTypedDict().stringify
def stringify() -> None:
Render TypedDict usage as a string.
TypeTypedDict().type_hint_annotations
@property
def type_hint_annotations() -> list[FakeAnnotation]:
Type annotations list from arguments and return type with internal types.
See also
TypedDictAttribute
class TypedDictAttribute():
def __init__(
name: str,
type_annotation: FakeAnnotation,
required: bool,
) -> None:
TypedDict attribute wrapper.
Arguments
name
- Attribute name.type_annotation
- Attribute type annotation.required
- Whether the attribute has to be set.
See also
TypedDictAttribute().get_type_annotation
def get_type_annotation() -> FakeAnnotation:
Get wrapped for non-required type annotation or raw type annotation.
See also
TypedDictAttribute().is_required
def is_required() -> bool:
Whether argument is required.
TypedDictAttribute().iterate_types
def iterate_types() -> Iterator[FakeAnnotation]:
Itera over type annotations.
See also
TypedDictAttribute().render
def render(parent_name: str = '') -> str:
Render attribute to use in class-based TypedDict definition.
Returns
A string with argument definition.