|
21 | 21 | """
|
22 | 22 |
|
23 | 23 | from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence
|
24 |
| -from typing import Any, Literal, cast, overload, reveal_type |
| 24 | +from typing import Any, Literal, cast, overload |
25 | 25 |
|
26 | 26 | type NestedMapping[K, V] = Mapping[K, NestedMappingNode[K, V]]
|
27 | 27 | type NestedMappingNode[K, V] = V | NestedMapping[K, V]
|
@@ -72,7 +72,7 @@ def flatten_dict_gen(
|
72 | 72 | raise KeySeparatorCollisionError(k, sep)
|
73 | 73 | concat_key = parent_key + sep + k if parent_key is not None else k
|
74 | 74 | if isinstance(v, Mapping):
|
75 |
| - yield from flatten_dict_gen(cast(NestedMapping[K, V], v), concat_key, sep) |
| 75 | + yield from flatten_dict_gen(cast("NestedMapping[K, V]", v), concat_key, sep) |
76 | 76 | else:
|
77 | 77 | yield concat_key, v
|
78 | 78 |
|
@@ -201,7 +201,7 @@ def set_deep[K, V](d: NestedMutableMapping[K, Any], keys: Sequence[K], value: An
|
201 | 201 | for key in keys[:-1]:
|
202 | 202 | try:
|
203 | 203 | # Raise TypeError if an existing key doesn't map to a dict
|
204 |
| - sub_dict = cast(NestedMutableMapping[K, V], sub_dict[key]) |
| 204 | + sub_dict = cast("NestedMutableMapping[K, V]", sub_dict[key]) |
205 | 205 | except KeyError:
|
206 | 206 | sub_dict[key] = sub_dict = {}
|
207 | 207 |
|
@@ -296,9 +296,9 @@ def map_leaves[K, V, W](
|
296 | 296 | for key in dict1:
|
297 | 297 | args = (d[key] for d in nested_dicts)
|
298 | 298 | if isinstance(dict1[key], Mapping):
|
299 |
| - dict_res[key] = map_leaves(func, *cast(Iterator[NestedMapping[K, V]], args)) |
| 299 | + dict_res[key] = map_leaves(func, *cast("Iterator[NestedMapping[K, V]]", args)) |
300 | 300 | else:
|
301 |
| - dict_res[key] = func(*cast(Iterator[V], args)) |
| 301 | + dict_res[key] = func(*cast("Iterator[V]", args)) |
302 | 302 |
|
303 | 303 | return dict_res
|
304 | 304 |
|
@@ -333,7 +333,7 @@ def filter_leaves[K, V](
|
333 | 333 | for key in nested_dict:
|
334 | 334 | sub_dict = nested_dict[key]
|
335 | 335 | if isinstance(sub_dict, Mapping):
|
336 |
| - filtered = filter_leaves(func, cast(NestedMapping[K, V], sub_dict), remove_empty) |
| 336 | + filtered = filter_leaves(func, cast("NestedMapping[K, V]", sub_dict), remove_empty) |
337 | 337 | if filtered or not remove_empty:
|
338 | 338 | dict_res[key] = filtered
|
339 | 339 | else:
|
|
0 commit comments