|
2 | 2 |
|
3 | 3 | import enum |
4 | 4 | from typing import FrozenSet, List, Mapping, NamedTuple, Optional, Tuple, Union |
| 5 | +from typing_extensions import TypeAlias |
5 | 6 |
|
6 | 7 |
|
7 | 8 | __all__ = [ |
@@ -55,19 +56,4 @@ class TrustLevel(enum.Enum): |
55 | 56 | UNDECIDED = "UNDECIDED" |
56 | 57 |
|
57 | 58 |
|
58 | | -# # Thanks @vanburgerberg - https://github.com/python/typing/issues/182 |
59 | | -# if TYPE_CHECKING: |
60 | | -# class JSONArray(list[JSONType], Protocol): # type: ignore |
61 | | -# __class__: Type[list[JSONType]] # type: ignore |
62 | | -# |
63 | | -# class JSONObject(dict[str, JSONType], Protocol): # type: ignore |
64 | | -# __class__: Type[dict[str, JSONType]] # type: ignore |
65 | | -# |
66 | | -# JSONType = Union[None, float, int, str, bool, JSONArray, JSONObject] |
67 | | - |
68 | | -# Sadly @vanburgerberg's solution doesn't seem to like Dict[str, bool], thus for now an incomplete JSON |
69 | | -# type with finite levels of depth. |
70 | | -Primitives = Union[None, float, int, str, bool] |
71 | | -JSONType2 = Union[Primitives, List[Primitives], Mapping[str, Primitives]] |
72 | | -JSONType1 = Union[Primitives, List[JSONType2], Mapping[str, JSONType2]] |
73 | | -JSONType = Union[Primitives, List[JSONType1], Mapping[str, JSONType1]] |
| 59 | +JSONType: TypeAlias = Union[Mapping[str, "JSONType"], List["JSONType"], str, int, float, bool, None] |
0 commit comments