Skip to content

Commit ca44a06

Browse files
committed
Revert "Add type hints using basedpyright"
This reverts commit 7aed8ec.
1 parent 7aed8ec commit ca44a06

File tree

8 files changed

+27
-42
lines changed

8 files changed

+27
-42
lines changed

inertia/http.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from functools import wraps
22
from http import HTTPStatus
33
from json import dumps as json_encode
4-
from typing import Any, Callable
54

65
from django.core.exceptions import ImproperlyConfigured
76
from django.http import HttpRequest, HttpResponse
@@ -66,11 +65,6 @@ def should_encrypt_history(self):
6665

6766

6867
class BaseInertiaResponseMixin:
69-
request: InertiaRequest
70-
component: str
71-
props: dict[str, Any]
72-
template_data: dict[str, Any]
73-
7468
def page_data(self):
7569
clear_history = validate_type(
7670
self.request.session.pop(INERTIA_SESSION_CLEAR_HISTORY, False),
@@ -153,7 +147,7 @@ def build_first_load(self, data):
153147
"inertia_layout": layout,
154148
**context,
155149
},
156-
self.request.request,
150+
self.request,
157151
using=None,
158152
)
159153

@@ -244,8 +238,8 @@ def clear_history(request):
244238
request.session[INERTIA_SESSION_CLEAR_HISTORY] = True
245239

246240

247-
def inertia(component: str):
248-
def decorator(func: Callable[..., HttpResponse | InertiaResponse | dict[str, Any]]):
241+
def inertia(component):
242+
def decorator(func):
249243
@wraps(func)
250244
def process_inertia_response(request, *args, **kwargs):
251245
props = func(request, *args, **kwargs)

inertia/middleware.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,5 @@ def is_stale_inertia_get(self, request):
5050
return request.method == "GET" and self.is_stale(request)
5151

5252
def force_refresh(self, request):
53-
# If the storage middleware is not defined, get_messages returns an empty list
54-
storage = messages.get_messages(request)
55-
if not isinstance(storage, list):
56-
storage.used = False
57-
53+
messages.get_messages(request).used = False
5854
return location(request.build_absolute_uri())

inertia/prop_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __call__(self):
1111

1212
class MergeableProp(ABC):
1313
@abstractmethod
14-
def should_merge(self) -> bool:
14+
def should_merge(self):
1515
pass
1616

1717

inertia/test.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class ClientWithLastResponse:
12-
def __init__(self, client: Client):
12+
def __init__(self, client):
1313
self.client = client
1414
self.last_response = None
1515

@@ -29,6 +29,10 @@ def setUp(self):
2929
def last_response(self):
3030
return self.inertia.last_response or self.client.last_response
3131

32+
def assertJSONResponse(self, response, json_obj):
33+
self.assertEqual(response.headers["Content-Type"], "application/json")
34+
self.assertEqual(response.json(), json_obj)
35+
3236

3337
class InertiaTestCase(BaseInertiaTestCase, TestCase):
3438
def setUp(self):
@@ -43,12 +47,11 @@ def tearDown(self):
4347
self.mock_inertia.stop()
4448

4549
def page(self):
46-
if self.mock_render.call_args:
47-
page_data = self.mock_render.call_args[0][1]["page"]
48-
elif response := self.last_response():
49-
page_data = response.content
50-
else:
51-
page_data = ""
50+
page_data = (
51+
self.mock_render.call_args[0][1]["page"]
52+
if self.mock_render.call_args
53+
else self.last_response().content
54+
)
5255

5356
return loads(page_data)
5457

@@ -72,10 +75,6 @@ def template_data(self):
7275
def component(self):
7376
return self.page()["component"]
7477

75-
def assertJSONResponse(self, response, json_obj):
76-
self.assertEqual(response.headers["Content-Type"], "application/json")
77-
self.assertEqual(response.json(), json_obj)
78-
7978
def assertIncludesProps(self, props):
8079
self.assertDictEqual(self.props(), {**self.props(), **props})
8180

inertia/tests/testapp/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
path("defer-group/", views.defer_group_test),
1515
path("merge/", views.merge_test),
1616
path("complex-props/", views.complex_props_test),
17-
path("share/", views.share_test), # type: ignore
17+
path("share/", views.share_test),
1818
path("inertia-redirect/", views.inertia_redirect_test),
1919
path("external-redirect/", views.external_redirect_test),
2020
path("encrypt-history/", views.encrypt_history_test),

inertia/tests/testapp/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def encrypt_history_false_test(request):
132132

133133
@inertia("TestComponent")
134134
def encrypt_history_type_error_test(request):
135-
encrypt_history(request, "foo") # pyright: ignore[reportArgumentType]
135+
encrypt_history(request, "foo")
136136
return {}
137137

138138

inertia/utils.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ def model_to_dict(model):
1313

1414

1515
class InertiaJsonEncoder(DjangoJSONEncoder):
16-
def default(self, o):
17-
if hasattr(o.__class__, "InertiaMeta"):
16+
def default(self, value):
17+
if hasattr(value.__class__, "InertiaMeta"):
1818
return {
19-
field: getattr(o, field) for field in o.__class__.InertiaMeta.fields
19+
field: getattr(value, field)
20+
for field in value.__class__.InertiaMeta.fields
2021
}
2122

22-
if isinstance(o, models.Model):
23-
return model_to_dict(o)
23+
if isinstance(value, models.Model):
24+
return model_to_dict(value)
2425

25-
if isinstance(o, QuerySet):
26+
if isinstance(value, QuerySet):
2627
return [
27-
(model_to_dict(obj) if isinstance(o.model, models.Model) else obj)
28-
for obj in o
28+
(model_to_dict(obj) if isinstance(value.model, models.Model) else obj)
29+
for obj in value
2930
]
3031

31-
return super().default(o)
32+
return super().default(value)
3233

3334

3435
def lazy(prop):

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ pytest = "^8.3.5"
3838
pytest-cov = "^6.0.0"
3939
pytest-django = "^4.10.0"
4040
ruff = "^0.11.2"
41-
django-stubs = "^5.2.1"
42-
basedpyright = "^1.30.1"
4341

4442
[tool.ruff.lint]
4543
select = [
@@ -56,6 +54,3 @@ unfixable = ["B", "SIM"]
5654
[tool.pytest.ini_options]
5755
DJANGO_SETTINGS_MODULE = "inertia.tests.settings"
5856
django_find_project = false
59-
60-
[tool.basedpyright]
61-
typeCheckingMode = "standard"

0 commit comments

Comments
 (0)