Skip to content

Commit 685f1d0

Browse files
committed
Handle all of the ruff errors in tests/
1 parent b43604e commit 685f1d0

30 files changed

+336
-580
lines changed

src/reactpy_django/clean.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def clean_user_data(verbosity: int = 1):
8888

8989
# Django doesn't support using QuerySets as an argument with cross-database relations.
9090
if user_model.objects.db != UserDataModel.objects.db:
91-
all_user_pks = list(all_user_pks) # type: ignore
91+
all_user_pks = list(all_user_pks)
9292

9393
user_data_objects = UserDataModel.objects.exclude(user_pk__in=all_user_pks)
9494

src/reactpy_django/components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _view_to_component(
155155
else:
156156
_request = HttpRequest()
157157
_request.method = "GET"
158-
resolved_view: Callable = import_module(view) if isinstance(view, str) else view # type: ignore[assignment]
158+
resolved_view: Callable = import_module(view) if isinstance(view, str) else view
159159

160160
# Render the view render within a hook
161161
@hooks.use_effect(

src/reactpy_django/hooks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async def execute_query() -> None:
139139
try:
140140
# Run the query
141141
if asyncio.iscoroutinefunction(query):
142-
new_data = await query(**kwargs) # type: ignore[call-arg]
142+
new_data = await query(**kwargs)
143143
else:
144144
new_data = await database_sync_to_async(query, thread_sensitive=thread_sensitive)(**kwargs)
145145

src/reactpy_django/models.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
class ComponentSession(models.Model):
1010
"""A model for storing component sessions."""
1111

12-
uuid = models.UUIDField(primary_key=True, editable=False, unique=True) # type: ignore
13-
params = models.BinaryField(editable=False) # type: ignore
14-
last_accessed = models.DateTimeField(auto_now=True) # type: ignore
12+
uuid = models.UUIDField(primary_key=True, editable=False, unique=True)
13+
params = models.BinaryField(editable=False)
14+
last_accessed = models.DateTimeField(auto_now=True)
1515

1616

1717
class Config(models.Model):
1818
"""A singleton model for storing ReactPy configuration."""
1919

20-
cleaned_at = models.DateTimeField(auto_now_add=True) # type: ignore
20+
cleaned_at = models.DateTimeField(auto_now_add=True)
2121

2222
def save(self, *args, **kwargs):
2323
"""Singleton save method."""
@@ -36,8 +36,8 @@ class UserDataModel(models.Model):
3636
# We can't store User as a ForeignKey/OneToOneField because it may not be in the same database
3737
# and Django does not allow cross-database relations. Also, since we can't know the type of the UserModel PK,
3838
# we store it as a string to normalize.
39-
user_pk = models.CharField(max_length=255, unique=True) # type: ignore
40-
data = models.BinaryField(null=True, blank=True) # type: ignore
39+
user_pk = models.CharField(max_length=255, unique=True)
40+
data = models.BinaryField(null=True, blank=True)
4141

4242

4343
@receiver(pre_delete, sender=get_user_model(), dispatch_uid="reactpy_delete_user_data")

src/reactpy_django/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def render_view(
7676
"""Ingests a Django view (class or function) and returns an HTTP response object."""
7777
# Convert class-based view to function-based view
7878
if getattr(view, "as_view", None):
79-
view = view.as_view() # type: ignore[union-attr]
79+
view = view.as_view()
8080

8181
# Async function view
8282
if iscoroutinefunction(view):
@@ -425,7 +425,7 @@ def vdom_or_component_to_string(
425425
"""Converts a VdomDict or component to an HTML string. If a string is provided instead, it will be
426426
automatically returned."""
427427
if isinstance(vdom_or_component, dict):
428-
return vdom_to_html(vdom_or_component) # type: ignore
428+
return vdom_to_html(vdom_or_component)
429429

430430
if hasattr(vdom_or_component, "render"):
431431
if not request:

tests/manage.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
"""Django's command-line utility for administrative tasks."""
3+
34
import os
45
import sys
56

@@ -11,11 +12,12 @@ def main():
1112
try:
1213
from django.core.management import execute_from_command_line
1314
except ImportError as exc:
14-
raise ImportError(
15+
msg = (
1516
"Couldn't import Django. Are you sure it's installed and "
1617
"available on your PYTHONPATH environment variable? Did you "
1718
"forget to activate a virtual environment?"
18-
) from exc
19+
)
20+
raise ImportError(msg) from exc
1921
execute_from_command_line(sys.argv)
2022

2123

tests/test_app/__init__.py

+3-19
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44

55
# Make sure the JS is always re-built before running the tests
66
js_dir = Path(__file__).parent.parent.parent / "src" / "js"
7-
static_dir = (
8-
Path(__file__).parent.parent.parent
9-
/ "src"
10-
/ "reactpy_django"
11-
/ "static"
12-
/ "reactpy_django"
13-
)
7+
static_dir = Path(__file__).parent.parent.parent / "src" / "reactpy_django" / "static" / "reactpy_django"
148
assert subprocess.run(["bun", "install"], cwd=str(js_dir), check=True).returncode == 0
159
assert (
1610
subprocess.run(
@@ -38,22 +32,12 @@ def copy_js_files(source_dir: Path, destination: Path) -> None:
3832
# Copy PyScript
3933
copy_js_files(
4034
js_dir / "node_modules" / "@pyscript" / "core" / "dist",
41-
Path(__file__).parent.parent.parent
42-
/ "src"
43-
/ "reactpy_django"
44-
/ "static"
45-
/ "reactpy_django"
46-
/ "pyscript",
35+
Path(__file__).parent.parent.parent / "src" / "reactpy_django" / "static" / "reactpy_django" / "pyscript",
4736
)
4837

4938

5039
# Copy MorphDOM
5140
copy_js_files(
5241
js_dir / "node_modules" / "morphdom" / "dist",
53-
Path(__file__).parent.parent.parent
54-
/ "src"
55-
/ "reactpy_django"
56-
/ "static"
57-
/ "reactpy_django"
58-
/ "morphdom",
42+
Path(__file__).parent.parent.parent / "src" / "reactpy_django" / "static" / "reactpy_django" / "morphdom",
5943
)

tests/test_app/admin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# ruff: noqa: RUF012
12
from django.contrib import admin
2-
from reactpy_django.models import ComponentSession, Config, UserDataModel
33

4+
from reactpy_django.models import ComponentSession, Config, UserDataModel
45
from test_app.models import (
56
AsyncForiegnChild,
67
AsyncRelationalChild,

tests/test_app/asgi.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616

1717
from channels.auth import AuthMiddlewareStack # noqa: E402
1818
from channels.routing import ProtocolTypeRouter, URLRouter # noqa: E402
19+
1920
from reactpy_django import REACTPY_WEBSOCKET_ROUTE # noqa: E402
2021

21-
application = ProtocolTypeRouter(
22-
{
23-
"http": http_asgi_app,
24-
"websocket": AuthMiddlewareStack(URLRouter([REACTPY_WEBSOCKET_ROUTE])),
25-
}
26-
)
22+
application = ProtocolTypeRouter({
23+
"http": http_asgi_app,
24+
"websocket": AuthMiddlewareStack(URLRouter([REACTPY_WEBSOCKET_ROUTE])),
25+
})

tests/test_app/channel_layers/components.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
# ruff: noqa: RUF029
12
from reactpy import component, hooks, html
3+
24
from reactpy_django.hooks import use_channel_layer
35

46

@@ -34,7 +36,7 @@ async def submit_event(event):
3436

3537

3638
@component
37-
def group_receiver(id: int):
39+
def group_receiver(id_number: int):
3840
state, set_state = hooks.use_state("None")
3941

4042
async def receiver(message):
@@ -43,8 +45,8 @@ async def receiver(message):
4345
use_channel_layer(receiver=receiver, group_name="group-messenger")
4446

4547
return html.div(
46-
{"id": f"group-receiver-{id}", "data-message": state},
47-
f"Group Message Receiver #{id}: {state}",
48+
{"id": f"group-receiver-{id_number}", "data-message": state},
49+
f"Group Message Receiver #{id_number}: {state}",
4850
)
4951

5052

0 commit comments

Comments
 (0)