Skip to content

Commit a85164c

Browse files
authored
Replace mypy and black with ruff (#262)
1 parent c5b5c81 commit a85164c

File tree

164 files changed

+915
-1228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+915
-1228
lines changed

.github/workflows/test-docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
- name: Check docs build
3030
run: hatch run docs:build
3131
- name: Check docs examples
32-
run: hatch run docs:check_examples
32+
run: hatch fmt docs --check

.github/workflows/test-python.yml

+15
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@ jobs:
3131
run: hatch test --python ${{ matrix.python-version }} --ds=test_app.settings_single_db -v
3232
- name: Run Multi-DB Tests
3333
run: hatch test --python ${{ matrix.python-version }} --ds=test_app.settings_multi_db -v
34+
35+
python-formatting:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: oven-sh/setup-bun@v2
40+
with:
41+
bun-version: latest
42+
- uses: actions/setup-python@v5
43+
with:
44+
python-version: 3.x
45+
- name: Install Python Dependencies
46+
run: pip install --upgrade pip hatch uv
47+
- name: Check Python formatting
48+
run: hatch fmt src tests --check

CHANGELOG.md

+3

docs/examples/python/configure-asgi.py renamed to docs/examples/python/configure_asgi.py

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

1111

1212
from channels.routing import ProtocolTypeRouter, URLRouter # noqa: E402
13+
1314
from reactpy_django import REACTPY_WEBSOCKET_ROUTE # noqa: E402
1415

15-
application = ProtocolTypeRouter(
16-
{
17-
"http": django_asgi_app,
18-
"websocket": URLRouter([REACTPY_WEBSOCKET_ROUTE]),
19-
}
20-
)
16+
application = ProtocolTypeRouter({
17+
"http": django_asgi_app,
18+
"websocket": URLRouter([REACTPY_WEBSOCKET_ROUTE]),
19+
})
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Broken load order, only used for linting
22
from channels.routing import ProtocolTypeRouter, URLRouter
3+
34
from reactpy_django import REACTPY_WEBSOCKET_ROUTE
45

56
django_asgi_app = ""
@@ -8,9 +9,7 @@
89
# start
910
from channels.auth import AuthMiddlewareStack # noqa: E402
1011

11-
application = ProtocolTypeRouter(
12-
{
13-
"http": django_asgi_app,
14-
"websocket": AuthMiddlewareStack(URLRouter([REACTPY_WEBSOCKET_ROUTE])),
15-
}
16-
)
12+
application = ProtocolTypeRouter({
13+
"http": django_asgi_app,
14+
"websocket": AuthMiddlewareStack(URLRouter([REACTPY_WEBSOCKET_ROUTE])),
15+
})

docs/examples/python/django-css.py renamed to docs/examples/python/django_css.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.components import django_css
34

45

docs/examples/python/django-css-external-link.py renamed to docs/examples/python/django_css_external_link.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
@component
55
def my_component():
66
return html.div(
7-
html.link(
8-
{"rel": "stylesheet", "href": "https://example.com/external-styles.css"}
9-
),
7+
html.link({"rel": "stylesheet", "href": "https://example.com/external-styles.css"}),
108
html.button("My Button!"),
119
)

docs/examples/python/django-js.py renamed to docs/examples/python/django_js.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.components import django_js
34

45

docs/examples/python/django-query-postprocessor.py renamed to docs/examples/python/django_query_postprocessor.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from example.models import TodoItem
21
from reactpy import component
2+
3+
from example.models import TodoItem
34
from reactpy_django.hooks import use_query
45
from reactpy_django.utils import django_query_postprocessor
56

docs/examples/python/django-router.py renamed to docs/examples/python/django_router.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from reactpy import component, html
2-
from reactpy_django.router import django_router
32
from reactpy_router import route
43

4+
from reactpy_django.router import django_router
5+
56

67
@component
78
def my_component():
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""This module exists only to satisfy type checkers.
2+
3+
Do not use the files in this module as examples within the docs."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""This module exists only to satisfy type checkers.
2+
3+
Do not use the files in this module as examples within the docs."""
4+
5+
6+
def child_component(): ...

docs/examples/python/example/views.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from django.shortcuts import render
1+
"""This module exists only to satisfy type checkers.
22
3+
Do not use the files in this module as examples within the docs."""
34

4-
def index(request):
5-
return render(request, "my_template.html")
5+
from python.hello_world_cbv import HelloWorld
6+
from python.hello_world_fbv import hello_world
7+
8+
__all__ = ["HelloWorld", "hello_world"]

docs/examples/python/example/urls.py renamed to docs/examples/python/first_urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.urls import path
2+
23
from example import views
34

45
urlpatterns = [

docs/examples/python/first_view.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.shortcuts import render
2+
3+
4+
def index(request):
5+
return render(request, "my_template.html")

docs/examples/python/hello_world_app_config_cbv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.apps import AppConfig
2-
from reactpy_django.utils import register_iframe
32

4-
from . import views
3+
from example import views
4+
from reactpy_django.utils import register_iframe
55

66

77
class ExampleAppConfig(AppConfig):

docs/examples/python/hello_world_app_config_fbv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.apps import AppConfig
2-
from reactpy_django.utils import register_iframe
32

4-
from . import views
3+
from example import views
4+
from reactpy_django.utils import register_iframe
55

66

77
class ExampleAppConfig(AppConfig):

docs/examples/python/pyodide-js-module.py renamed to docs/examples/python/pyodide_js_module.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
@component
66
def root():
7-
8-
def onClick(event):
7+
def on_click(event):
98
js.document.title = "New window title"
109

11-
return html.button({"onClick": onClick}, "Click Me!")
10+
return html.button({"onClick": on_click}, "Click Me!")

docs/examples/python/pyscript-component-initial-object.py renamed to docs/examples/python/pyscript_component_initial_object.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.components import pyscript_component
34

45

docs/examples/python/pyscript-component-initial-string.py renamed to docs/examples/python/pyscript_component_initial_string.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.components import pyscript_component
34

45

docs/examples/python/pyscript-component-multiple-files-root.py renamed to docs/examples/python/pyscript_component_multiple_files_root.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.components import pyscript_component
34

45

docs/examples/python/pyscript-component-root.py renamed to docs/examples/python/pyscript_component_root.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.components import pyscript_component
34

45

docs/examples/python/pyscript-multiple-files-root.py renamed to docs/examples/python/pyscript_multiple_files_root.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
from typing import TYPE_CHECKING
2-
31
from reactpy import component, html
42

5-
if TYPE_CHECKING:
6-
from .child import child_component
3+
from example.components import child_component
74

85

96
@component

docs/examples/python/pyscript-ssr-parent.py renamed to docs/examples/python/pyscript_ssr_parent.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.components import pyscript_component
34

45

docs/examples/python/pyscript-tag.py renamed to docs/examples/python/pyscript_tag.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.html import pyscript
34

45
example_source_code = """

docs/examples/python/register-component.py renamed to docs/examples/python/register_component.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.apps import AppConfig
2+
23
from reactpy_django.utils import register_component
34

45

docs/examples/python/use-channel-layer.py renamed to docs/examples/python/use_channel_layer.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, hooks, html
2+
23
from reactpy_django.hooks import use_channel_layer
34

45

docs/examples/python/use-channel-layer-group.py renamed to docs/examples/python/use_channel_layer_group.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, hooks, html
2+
23
from reactpy_django.hooks import use_channel_layer
34

45

docs/examples/python/use-channel-layer-signal-receiver.py renamed to docs/examples/python/use_channel_layer_signal_receiver.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, hooks, html
2+
23
from reactpy_django.hooks import use_channel_layer
34

45

docs/examples/python/use-connection.py renamed to docs/examples/python/use_connection.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.hooks import use_connection
34

45

docs/examples/python/use-location.py renamed to docs/examples/python/use_location.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.hooks import use_location
34

45

docs/examples/python/use-mutation.py renamed to docs/examples/python/use_mutation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from example.models import TodoItem
21
from reactpy import component, html
2+
3+
from example.models import TodoItem
34
from reactpy_django.hooks import use_mutation
45

56

Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from reactpy import component
2+
23
from reactpy_django.hooks import use_mutation
34

45

5-
def example_mutation(value: int, other_value: bool = False):
6-
...
6+
def example_mutation(value: int, other_value: bool = False): ...
77

88

99
@component
1010
def my_component():
1111
mutation = use_mutation(example_mutation)
1212

1313
mutation(123, other_value=True)
14-
15-
...

docs/examples/python/use-mutation-query-refetch.py renamed to docs/examples/python/use_mutation_query_refetch.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from example.models import TodoItem
21
from reactpy import component, html
2+
3+
from example.models import TodoItem
34
from reactpy_django.hooks import use_mutation, use_query
45

56

@@ -26,9 +27,7 @@ def submit_event(event):
2627
elif item_query.error or not item_query.data:
2728
rendered_items = html.h2("Error when loading!")
2829
else:
29-
rendered_items = html.ul(
30-
html.li(item.text, key=item.pk) for item in item_query.data
31-
)
30+
rendered_items = html.ul(html.li(item.text, key=item.pk) for item in item_query.data)
3231

3332
# Handle all possible mutation states
3433
if item_mutation.loading:

docs/examples/python/use-mutation-reset.py renamed to docs/examples/python/use_mutation_reset.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from example.models import TodoItem
21
from reactpy import component, html
2+
3+
from example.models import TodoItem
34
from reactpy_django.hooks import use_mutation
45

56

docs/examples/python/use-mutation-thread-sensitive.py renamed to docs/examples/python/use_mutation_thread_sensitive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from reactpy import component, html
2+
23
from reactpy_django.hooks import use_mutation
34

45

56
def execute_thread_safe_mutation(text):
67
"""This is an example mutation function that does some thread-safe operation."""
7-
pass
88

99

1010
@component

docs/examples/python/use-origin.py renamed to docs/examples/python/use_origin.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component, html
2+
23
from reactpy_django.hooks import use_origin
34

45

docs/examples/python/use-query.py renamed to docs/examples/python/use_query.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from channels.db import database_sync_to_async
2-
from example.models import TodoItem
32
from reactpy import component, html
3+
4+
from example.models import TodoItem
45
from reactpy_django.hooks import use_query
56

67

@@ -17,8 +18,6 @@ def todo_list():
1718
elif item_query.error or not item_query.data:
1819
rendered_items = html.h2("Error when loading!")
1920
else:
20-
rendered_items = html.ul(
21-
[html.li(item.text, key=item.pk) for item in item_query.data]
22-
)
21+
rendered_items = html.ul([html.li(item.text, key=item.pk) for item in item_query.data])
2322

2423
return html.div("Rendered items: ", rendered_items)

docs/examples/python/use-query-args.py renamed to docs/examples/python/use_query_args.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component
2+
23
from reactpy_django.hooks import use_query
34

45

docs/examples/python/use-query-postprocessor-change.py renamed to docs/examples/python/use_query_postprocessor_change.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from reactpy import component
2+
23
from reactpy_django.hooks import use_query
34

45

@@ -11,7 +12,6 @@ def my_postprocessor(data, example_kwarg=True):
1112

1213
def execute_io_intensive_operation():
1314
"""This is an example query function that does something IO intensive."""
14-
pass
1515

1616

1717
@component

docs/examples/python/use-query-postprocessor-disable.py renamed to docs/examples/python/use_query_postprocessor_disable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from reactpy import component
2+
23
from reactpy_django.hooks import use_query
34

45

56
def execute_io_intensive_operation():
67
"""This is an example query function that does something IO intensive."""
7-
pass
88

99

1010
@component

docs/examples/python/use-query-postprocessor-kwargs.py renamed to docs/examples/python/use_query_postprocessor_kwargs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from example.models import TodoItem
21
from reactpy import component
2+
3+
from example.models import TodoItem
34
from reactpy_django.hooks import use_query
45

56

0 commit comments

Comments
 (0)