Skip to content

Commit aee6179

Browse files
committed
Improve code cleaning for python 3.10+
1 parent 6ac9a8e commit aee6179

File tree

20 files changed

+50
-42
lines changed

20 files changed

+50
-42
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ reworked authentication system, improved type annotations, and more flexible con
3030
Getting started
3131
---------------
3232

33-
.. important:: django-modern-rpc requires Python 3.10+ and Django 3.2+. If you need to install it in environment with
33+
.. important:: django-modern-rpc requires Python 3.10+ and Django 4.2+. If you need to install it in environment with
3434
older Python / Django versions, you must install a previous release. See :ref:`Changelog` for more information.
3535

3636
Installing the library and configuring a Django project to use it can be achieved in a few minutes. Follow

modernrpc/auth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import base64
44
import functools
5-
from typing import TYPE_CHECKING, Callable
5+
from typing import TYPE_CHECKING
66
from urllib.parse import unquote
77

88
if TYPE_CHECKING:
9+
from collections.abc import Callable
10+
911
from django.http import HttpRequest
1012

1113

modernrpc/compat.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import sys
22
import types
33
import typing
4-
from types import NoneType # noqa: F401
54

65
import django
76
from django.views.decorators.csrf import csrf_exempt
87

98
if typing.TYPE_CHECKING:
10-
from typing import TypeAlias # noqa: F401
11-
129
if sys.version_info >= (3, 11):
1310
from typing import Self
1411
else:

modernrpc/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
from collections import OrderedDict, defaultdict
66
from dataclasses import dataclass
7-
from typing import TYPE_CHECKING, Any, Iterable
7+
from typing import TYPE_CHECKING, Any
88

99
from asgiref.sync import async_to_sync, iscoroutinefunction, sync_to_async
1010
from django.utils.functional import cached_property
@@ -21,6 +21,8 @@
2121
from modernrpc.introspection import DocstringParser, Introspector
2222

2323
if TYPE_CHECKING:
24+
from collections.abc import Iterable
25+
2426
from django.http import HttpRequest
2527

2628
from modernrpc.handler import RpcHandler

modernrpc/helpers.py

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

33
import datetime
44
import xmlrpc.client
5-
from typing import TYPE_CHECKING, Any, Iterable, Sequence
5+
from typing import TYPE_CHECKING, Any
66

77
from modernrpc.constants import NOT_SET
88

99
if TYPE_CHECKING:
10+
from collections.abc import Callable, Iterable, Sequence
1011
from enum import Flag
11-
from typing import Callable
1212

1313

1414
def check_flags_compatibility(a: Flag, b: Flag) -> bool:

modernrpc/jsonrpc/backends/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Iterable, Protocol
3+
from typing import TYPE_CHECKING, Protocol
44

55
if TYPE_CHECKING:
6+
from collections.abc import Iterable
7+
68
from modernrpc.jsonrpc.handler import JsonRpcRequest, JsonRpcResult
79

810

modernrpc/jsonrpc/backends/json.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import json
44
from functools import cached_property
55
from json import JSONDecodeError
6-
from typing import TYPE_CHECKING, Iterable
6+
from typing import TYPE_CHECKING
77

88
from django.core.serializers.json import DjangoJSONEncoder
99
from django.utils.module_loading import import_string
1010

1111
from modernrpc.exceptions import RPCMarshallingError, RPCParseError
1212

1313
if TYPE_CHECKING:
14+
from collections.abc import Iterable
15+
1416
from modernrpc.jsonrpc.handler import JsonRpcRequest, JsonRpcResult
1517
from modernrpc.types import CustomKwargs, DictStrAny
1618

modernrpc/jsonrpc/backends/marshalling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from types import NoneType
34
from typing import TYPE_CHECKING, cast, overload
45

56
from modernrpc.constants import NOT_SET
@@ -30,7 +31,7 @@ def validate_dict_request(self, request_data: DictStrAny) -> None:
3031
# Notification request won't have "id" field
3132
# None is also an allowed value. Both cases are valid
3233
request_id = request_data.get("id")
33-
if request_id is not None and type(request_id) not in (int, float, str):
34+
if type(request_id) not in (NoneType, int, float, str):
3435
raise RPCInvalidRequest(
3536
'Parameter "id" has an unsupported value. According to JSON-RPC 2.0 standard, it must '
3637
f"be a String, a Number or a Null value. Found: {type(request_id)}"

modernrpc/jsonrpc/backends/orjson.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from __future__ import annotations
22

33
from functools import cached_property
4-
from typing import TYPE_CHECKING, Iterable
4+
from typing import TYPE_CHECKING
55

66
import orjson
77
from django.utils.module_loading import import_string
88

99
from modernrpc.exceptions import RPCMarshallingError, RPCParseError
1010

1111
if TYPE_CHECKING:
12+
from collections.abc import Iterable
13+
1214
from modernrpc.jsonrpc.handler import JsonRpcRequest, JsonRpcResult
1315
from modernrpc.types import CustomKwargs, DictStrAny
1416

modernrpc/jsonrpc/backends/rapidjson.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from functools import cached_property
4-
from typing import TYPE_CHECKING, Iterable
4+
from typing import TYPE_CHECKING
55

66
import rapidjson
77
from django.utils.module_loading import import_string
@@ -10,6 +10,8 @@
1010
from modernrpc.exceptions import RPCMarshallingError, RPCParseError
1111

1212
if TYPE_CHECKING:
13+
from collections.abc import Iterable
14+
1315
from modernrpc.jsonrpc.handler import JsonRpcRequest, JsonRpcResult
1416
from modernrpc.types import CustomKwargs, DictStrAny
1517

0 commit comments

Comments
 (0)