Skip to content

Commit f89ae3a

Browse files
committed
Make JsonLibrary be a protocol.
1 parent 678c491 commit f89ae3a

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

domdf_python_tools/typing.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
# stdlib
2727
import os
2828
import pathlib
29-
import sys
3029
from decimal import Decimal
3130
from json import JSONDecoder, JSONEncoder
32-
from types import ModuleType
3331
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
3432

33+
# 3rd party
34+
from typing_extensions import Protocol
35+
3536
__all__ = ["PathLike", "AnyNumber", "check_membership", "JsonLibrary"]
3637

3738
#: Type hint for objects that represent filesystem paths.
@@ -61,7 +62,7 @@ def check_membership(obj: Any, type_: Union[Type, object]) -> bool:
6162
return isinstance(obj, type_.__args__) # type: ignore
6263

6364

64-
class JsonLibrary(ModuleType):
65+
class JsonLibrary(Protocol):
6566
"""
6667
Type hint for functions that take a JSON serialisation-deserialisation library as an argument.
6768
@@ -99,14 +100,9 @@ def dumps(
99100
:param kwds:
100101
"""
101102

102-
if sys.version_info >= (3, 6):
103-
_LoadsString = Union[str, bytes]
104-
else:
105-
_LoadsString = str
106-
107103
@staticmethod
108104
def loads(
109-
s: _LoadsString,
105+
s: Union[str, bytes],
110106
*,
111107
cls: Optional[Type[JSONDecoder]] = ...,
112108
object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ...,

0 commit comments

Comments
 (0)