Skip to content

Commit 73974c8

Browse files
committed
[types] Perform changes on type hints based on ty warnings
1 parent 77c41cd commit 73974c8

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

modernrpc/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def async_csrf_exempt(view):
2222
if sys.version_info >= (3, 14):
2323

2424
def is_union_type(_type: type):
25-
return isinstance(_type, typing.Union)
25+
return isinstance(_type, types.UnionType)
2626

2727
elif sys.version_info >= (3, 10):
2828

modernrpc/xmlrpc/backends/marshalling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
NoneType = type(None) # type: ignore[misc]
2525

2626

27-
class ElementTypeProtocol(Protocol, Iterable):
27+
class ElementTypeProtocol(Iterable, Protocol):
2828
"""
2929
Base protocol for XML element types. This reflects the API of both the xml.etree and the lxml library.
3030
Unfortunately, since both libraries share the same interface without inheriting a common base class, we

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def factory(
7676

7777
@pytest.fixture
7878
def jsonrpc_batch_rf(rf) -> Callable[..., HttpRequest]:
79-
def factory(path="/rpc", content_type="application/json", requests: list[str, tuple, bool] | None = None):
79+
def factory(path="/rpc", content_type="application/json", requests: list[tuple[str, tuple, bool]] | None = None):
8080
data = [
8181
build_json_rpc_request_data(method=method_name, params=params, is_notification=is_notification)
8282
for method_name, params, is_notification in requests or []

tests/test_proc_wrapper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class TestArgsTypeHint:
297297
@pytest.fixture
298298
def wrapper(self):
299299
def typed_args(a: int, b: str, c: list | float) -> dict | list:
300-
pass
300+
return []
301301

302302
return ProcedureWrapper(typed_args)
303303

@@ -345,6 +345,7 @@ def typehints_and_standard_docstring(a: str, b, c: float) -> float:
345345
:param c: param C
346346
:return: A decimal value
347347
"""
348+
return 1.33
348349

349350
return ProcedureWrapper(typehints_and_standard_docstring)
350351

@@ -423,6 +424,7 @@ def typehints_and_types_docstring(x: list, y: str) -> dict:
423424
:type y: int
424425
:rtype: str
425426
"""
427+
return {}
426428

427429
return ProcedureWrapper(typehints_and_types_docstring)
428430

@@ -453,8 +455,9 @@ class TestWithTypeHintAndKwargs:
453455

454456
@pytest.fixture
455457
def wrapper(self):
456-
def with_kwargs(x: list, y: str, **kwargs) -> dict:
458+
def with_kwargs(x: list, y: str, **kwargs) -> str:
457459
"""This is the docstring part of the function"""
460+
return "abcdefgh"
458461

459462
return ProcedureWrapper(with_kwargs)
460463

@@ -470,7 +473,7 @@ def test_arguments(self, wrapper):
470473
}
471474

472475
def test_returns(self, wrapper):
473-
assert wrapper.returns == ProcedureArgDocs(docstring="", doc_type="", type_hint=dict)
476+
assert wrapper.returns == ProcedureArgDocs(docstring="", doc_type="", type_hint=str)
474477

475478
def test_default_html_doc(self, wrapper):
476479
assert wrapper.text_doc == "This is the docstring part of the function"

0 commit comments

Comments
 (0)