Skip to content

Commit 682fa6b

Browse files
committed
Simplified the JSONType type
1 parent 25bbf31 commit 682fa6b

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1111

1212
### Changed
1313
- Removed type annotations from enum members in accordance with a new mypy rule
14+
- Simplified the `JSONObject` type now that recursive aliases are properly supported
1415

1516
## [1.2.0] - 15th of October, 2024
1617

omemo/types.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import enum
44
from typing import FrozenSet, List, Mapping, NamedTuple, Optional, Tuple, Union
5+
from typing_extensions import TypeAlias
56

67

78
__all__ = [
@@ -55,19 +56,4 @@ class TrustLevel(enum.Enum):
5556
UNDECIDED = "UNDECIDED"
5657

5758

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

Comments
 (0)