Type of TypedDict object {'k1': v1, ..., 'kn': vn}. A TypedDict object is a dictionary with specific string (literal) keys. Each key has a value with a distinct type that depends on the key. TypedDict objects are normal dict objects at runtime. A TypedDictType can be either named o
| 2924 | |
| 2925 | |
| 2926 | class TypedDictType(ProperType): |
| 2927 | """Type of TypedDict object {'k1': v1, ..., 'kn': vn}. |
| 2928 | |
| 2929 | A TypedDict object is a dictionary with specific string (literal) keys. Each |
| 2930 | key has a value with a distinct type that depends on the key. TypedDict objects |
| 2931 | are normal dict objects at runtime. |
| 2932 | |
| 2933 | A TypedDictType can be either named or anonymous. If it's anonymous, its |
| 2934 | fallback will be typing_extensions._TypedDict (Instance). _TypedDict is a subclass |
| 2935 | of Mapping[str, object] and defines all non-mapping dict methods that TypedDict |
| 2936 | supports. Some dict methods are unsafe and not supported. _TypedDict isn't defined |
| 2937 | at runtime. |
| 2938 | |
| 2939 | If a TypedDict is named, its fallback will be an Instance of the named type |
| 2940 | (ex: "Point") whose TypeInfo has a typeddict_type that is anonymous. This |
| 2941 | is similar to how named tuples work. |
| 2942 | |
| 2943 | TODO: The fallback structure is perhaps overly complicated. |
| 2944 | """ |
| 2945 | |
| 2946 | __slots__ = ( |
| 2947 | "items", |
| 2948 | "required_keys", |
| 2949 | "readonly_keys", |
| 2950 | "fallback", |
| 2951 | "extra_items_from", |
| 2952 | "to_be_mutated", |
| 2953 | ) |
| 2954 | |
| 2955 | items: dict[str, Type] # item_name -> item_type |
| 2956 | required_keys: set[str] |
| 2957 | readonly_keys: set[str] |
| 2958 | fallback: Instance |
| 2959 | |
| 2960 | extra_items_from: list[ProperType] # only used during semantic analysis |
| 2961 | to_be_mutated: bool # only used in a plugin for `.update`, `|=`, etc |
| 2962 | |
| 2963 | def __init__( |
| 2964 | self, |
| 2965 | items: dict[str, Type], |
| 2966 | required_keys: set[str], |
| 2967 | readonly_keys: set[str], |
| 2968 | fallback: Instance, |
| 2969 | line: int = -1, |
| 2970 | column: int = -1, |
| 2971 | ) -> None: |
| 2972 | super().__init__(line, column) |
| 2973 | self.items = items |
| 2974 | self.required_keys = required_keys |
| 2975 | self.readonly_keys = readonly_keys |
| 2976 | self.fallback = fallback |
| 2977 | self.can_be_true = len(self.items) > 0 |
| 2978 | self.can_be_false = len(self.required_keys) == 0 |
| 2979 | self.extra_items_from = [] |
| 2980 | self.to_be_mutated = False |
| 2981 | |
| 2982 | def accept(self, visitor: TypeVisitor[T]) -> T: |
| 2983 | return visitor.visit_typeddict_type(self) |
no outgoing calls
no test coverage detected
searching dependent graphs…