TypeTypedDict

Auto-generated documentation for mypy_boto3_builder.type_annotations.type_typed_dict module.

Wrapper for typing/typing_extensions.TypedDict type annotations.

TypeTypedDict

[find in source code]

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

[find in source code]

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

[find in source code]

def copy() -> 'TypeTypedDict':

Create a copy of type annotation wrapper.

TypeTypedDict().get_attribute

[find in source code]

def get_attribute(name: str) -> TypedDictAttribute:

Find attribute by name.

Arguments

  • name - Attribute name.

Returns

Found attribute.

See also

TypeTypedDict().get_children_literals

[find in source code]

def get_children_literals(
    processed: Iterable['TypeTypedDict'] = tuple(),
) -> set[TypeLiteral]:

Extract required TypeLiteral list from attributes.

See also

TypeTypedDict().get_children_typed_dicts

[find in source code]

def get_children_typed_dicts() -> set['TypeTypedDict']:

Extract required TypeTypedDict list from attributes.

TypeTypedDict().get_children_types

[find in source code]

def get_children_types() -> set[FakeAnnotation]:

Extract required type annotations from attributes.

See also

TypeTypedDict().get_import_record

[find in source code]

def get_import_record() -> ImportRecord:

Get import record required for using type annotation.

See also

TypeTypedDict().get_local_types

[find in source code]

def get_local_types() -> list[FakeAnnotation]:

Get internal types generated by builder.

See also

TypeTypedDict().get_optional

[find in source code]

def get_optional() -> list[TypedDictAttribute]:

Get a list of optional attributes.

See also

TypeTypedDict().get_required

[find in source code]

def get_required() -> list[TypedDictAttribute]:

Get a list of required attributes.

See also

TypeTypedDict().get_sort_key

[find in source code]

def get_sort_key() -> str:

Sort Typed Dicts by name.

TypeTypedDict.get_typing_import_record

[find in source code]

@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

[find in source code]

def has_both() -> bool:

Whether TypedDict has both optional and required keys.

TypeTypedDict().has_optional

[find in source code]

def has_optional() -> bool:

Whether TypedDict has optional keys.

TypeTypedDict().has_required

[find in source code]

def has_required() -> bool:

Whether TypedDict has required keys.

TypeTypedDict().is_dict

[find in source code]

def is_dict() -> bool:

Always True as it is a TypedDict.

TypeTypedDict().is_same

[find in source code]

def is_same(other: 'TypeTypedDict') -> bool:

Check whether typed dict attributes are the same as other.

TypeTypedDict().is_stringified

[find in source code]

def is_stringified() -> bool:

Whether TypedDict usage should be rendered as a string.

TypeTypedDict().is_typed_dict

[find in source code]

def is_typed_dict() -> bool:

Always True as it is a TypedDict.

TypeTypedDict().iterate_children

[find in source code]

def iterate_children() -> Iterator[TypedDictAttribute]:

Iterate over children from required to optional.

See also

TypeTypedDict().render

[find in source code]

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

[find in source code]

def replace_self_references() -> None:

Replace self refenrences with Dict[str, Any] to avoid circular dependencies.

TypeTypedDict().requires_safe_render

[find in source code]

@property
def requires_safe_render() -> bool:

Whether TypedDict has reserved words and has to be rendered safely.

TypeTypedDict().stringify

[find in source code]

def stringify() -> None:

Render TypedDict usage as a string.

TypeTypedDict().type_hint_annotations

[find in source code]

@property
def type_hint_annotations() -> list[FakeAnnotation]:

Type annotations list from arguments and return type with internal types.

See also

TypedDictAttribute

[find in source code]

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

[find in source code]

def get_type_annotation() -> FakeAnnotation:

Get wrapped for non-required type annotation or raw type annotation.

See also

TypedDictAttribute().is_required

[find in source code]

def is_required() -> bool:

Whether argument is required.

TypedDictAttribute().iterate_types

[find in source code]

def iterate_types() -> Iterator[FakeAnnotation]:

Itera over type annotations.

See also

TypedDictAttribute().render

[find in source code]

def render(parent_name: str = '') -> str:

Render attribute to use in class-based TypedDict definition.

Returns

A string with argument definition.