Skip to content

Commit e025f05

Browse files
committed
more ruff fixes
1 parent ffac74a commit e025f05

Some content is hidden

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

74 files changed

+146
-264
lines changed

.github/workflows/.nox-session.yml renamed to .github/workflows/.hatch-run.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
name: Nox Session
1+
name: hatch-run
22

33
on:
44
workflow_call:
55
inputs:
66
job-name:
77
required: true
88
type: string
9-
nox-args:
9+
hatch-run:
1010
required: true
1111
type: string
12-
nox-session-args:
13-
required: false
14-
type: string
1512
runs-on-array:
1613
required: false
1714
type: string
@@ -29,7 +26,7 @@ on:
2926
required: false
3027

3128
jobs:
32-
nox-session:
29+
hatch:
3330
name: ${{ format(inputs.job-name, matrix.python-version, matrix.runs-on) }}
3431
strategy:
3532
matrix:
@@ -55,4 +52,4 @@ jobs:
5552
NODE_AUTH_TOKEN: ${{ secrets.node-auth-token }}
5653
PYPI_USERNAME: ${{ secrets.pypi-username }}
5754
PYPI_PASSWORD: ${{ secrets.pypi-password }}
58-
run: nox ${{ inputs.nox-args }} --stop-on-first-error -- ${{ inputs.nox-session-args }}
55+
run: hatch run ${{ inputs.hatch-run }}

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ on:
1212

1313
jobs:
1414
python-exhaustive:
15-
uses: ./.github/workflows/.nox-session.yml
15+
uses: ./.github/workflows/.hatch-run.yml
1616
with:
1717
job-name: "python-{0}"
18-
nox-args: "-t check-python"
18+
hatch-run: "-t check-python"
1919
nox-session-args: "--pytest --maxfail=3 --reruns 3"
2020
python-environments:
2121
uses: ./.github/workflows/.nox-session.yml
@@ -24,7 +24,7 @@ jobs:
2424
nox-args: "-s check-python-tests"
2525
nox-session-args: "--no-cov --pytest --maxfail=3 --reruns 3"
2626
runs-on-array: '["ubuntu-latest", "macos-latest", "windows-latest"]'
27-
python-version-array: '["3.7", "3.8", "3.9", "3.10", "3.11"]'
27+
python-version-array: '["3.9", "3.10", "3.11"]'
2828
docs:
2929
uses: ./.github/workflows/.nox-session.yml
3030
with:

docs/app.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33

44
from sanic import Sanic, response
55

6+
from docs.examples import get_normalized_example_name, load_examples
67
from reactpy import component
78
from reactpy.backend.sanic import Options, configure, use_request
89
from reactpy.core.types import ComponentConstructor
910

10-
from .examples import get_normalized_example_name, load_examples
11-
12-
1311
HERE = Path(__file__).parent
1412
REACTPY_MODEL_SERVER_URL_PREFIX = "/_reactpy"
1513

@@ -46,7 +44,7 @@ def make_app():
4644
app.static("/docs", str(HERE / "build"))
4745

4846
@app.route("/")
49-
async def forward_to_index(request):
47+
async def forward_to_index(_):
5048
return response.redirect("/docs/index.html")
5149

5250
configure(

docs/examples.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from __future__ import annotations
22

3+
from collections.abc import Iterator
34
from io import StringIO
45
from pathlib import Path
56
from traceback import format_exc
6-
from typing import Callable, Iterator
7+
from typing import Callable
78

89
import reactpy
910
from reactpy.types import ComponentType
1011

11-
1212
HERE = Path(__file__)
1313
SOURCE_DIR = HERE.parent / "source"
1414
CONF_FILE = SOURCE_DIR / "conf.py"
@@ -148,7 +148,6 @@ def __init__(self, max_lines: int = 10):
148148

149149
def set_callback(self, function: Callable[[str], None]) -> None:
150150
self._callback = function
151-
return None
152151

153152
def getvalue(self) -> str:
154153
return "".join(self._lines)

docs/source/_exts/async_doctest.py

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from sphinx.ext.doctest import DocTestBuilder
77
from sphinx.ext.doctest import setup as doctest_setup
88

9-
109
test_template = """
1110
import asyncio as __test_template_asyncio
1211
@@ -41,10 +40,8 @@ def test_runner(self) -> DocTestRunner:
4140
@test_runner.setter
4241
def test_runner(self, value: DocTestRunner) -> None:
4342
self._test_runner = TestRunnerWrapper(value)
44-
return None
4543

4644

4745
def setup(app: Sphinx) -> None:
4846
doctest_setup(app)
4947
app.add_builder(AsyncDoctestBuilder, override=True)
50-
return None

docs/source/_exts/autogen_api_docs.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
22

33
import sys
4+
from collections.abc import Collection, Iterator
45
from pathlib import Path
5-
from typing import Collection, Iterator
66

77
from sphinx.application import Sphinx
88

9-
109
HERE = Path(__file__).parent
1110
SRC = HERE.parent.parent.parent / "src"
1211
PYTHON_PACKAGE = SRC / "reactpy"
@@ -83,7 +82,9 @@ def get_module_name(path: Path) -> str:
8382

8483
def get_section_symbol(path: Path) -> str:
8584
rel_path_parts = path.relative_to(PYTHON_PACKAGE).parts
86-
assert len(rel_path_parts) < len(SECTION_SYMBOLS), "package structure is too deep"
85+
if len(rel_path_parts) < len(SECTION_SYMBOLS):
86+
msg = "package structure is too deep"
87+
raise RuntimeError(msg)
8788
return SECTION_SYMBOLS[len(rel_path_parts)]
8889

8990

docs/source/_exts/build_custom_js.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from sphinx.application import Sphinx
55

6-
76
SOURCE_DIR = Path(__file__).parent.parent
87
CUSTOM_JS_DIR = SOURCE_DIR / "_custom_js"
98

docs/source/_exts/custom_autosectionlabel.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from sphinx.util import logging
1818
from sphinx.util.nodes import clean_astext
1919

20-
2120
logger = logging.getLogger(__name__)
2221

2322

docs/source/_exts/reactpy_example.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ def run(self):
4141
ex_files = get_example_files_by_name(example_name)
4242
if not ex_files:
4343
src_file, line_num = self.get_source_info()
44-
raise ValueError(
45-
f"Missing example named {example_name!r} "
46-
f"referenced by document {src_file}:{line_num}"
47-
)
44+
msg = f"Missing example named {example_name!r} referenced by document {src_file}:{line_num}"
45+
raise ValueError(msg)
4846

4947
labeled_tab_items: list[tuple[str, Any]] = []
5048
if len(ex_files) == 1:
@@ -114,7 +112,8 @@ def _literal_include(path: Path, linenos: bool):
114112
".json": "json",
115113
}[path.suffix]
116114
except KeyError:
117-
raise ValueError(f"Unknown extension type {path.suffix!r}")
115+
msg = f"Unknown extension type {path.suffix!r}"
116+
raise ValueError(msg) from None
118117

119118
return _literal_include_template.format(
120119
name=str(path.relative_to(SOURCE_DIR)),

docs/source/_exts/reactpy_view.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from docs.examples import get_normalized_example_name
99

10-
1110
_REACTPY_EXAMPLE_HOST = os.environ.get("REACTPY_DOC_EXAMPLE_SERVER_HOST", "")
1211
_REACTPY_STATIC_HOST = os.environ.get("REACTPY_DOC_STATIC_SERVER_HOST", "/docs").rstrip(
1312
"/"

docs/source/conf.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Configuration file for the Sphinx documentation builder.
43
#
@@ -10,7 +9,6 @@
109
from doctest import DONT_ACCEPT_TRUE_FOR_1, ELLIPSIS, NORMALIZE_WHITESPACE
1110
from pathlib import Path
1211

13-
1412
# -- Path Setup --------------------------------------------------------------
1513

1614
THIS_DIR = Path(__file__).parent
@@ -32,7 +30,7 @@
3230
"a single line of Javascript. It can be run standalone, in a Jupyter Notebook, or "
3331
"as part of an existing application."
3432
)
35-
copyright = "2023, Ryan Morshead"
33+
copyright = "2023, Ryan Morshead" # noqa: A001
3634
author = "Ryan Morshead"
3735

3836
# -- Common External Links ---------------------------------------------------

docs/source/guides/adding-interactivity/components-with-state/_examples/adding_state_variable/main.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from reactpy import component, hooks, html, run
55

6-
76
HERE = Path(__file__)
87
DATA_PATH = HERE.parent / "data.json"
98
sculpture_data = json.loads(DATA_PATH.read_text())

docs/source/guides/adding-interactivity/components-with-state/_examples/isolated_state/main.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from reactpy import component, hooks, html, run
55

6-
76
HERE = Path(__file__)
87
DATA_PATH = HERE.parent / "data.json"
98
sculpture_data = json.loads(DATA_PATH.read_text())

docs/source/guides/adding-interactivity/components-with-state/_examples/multiple_state_variables/main.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from reactpy import component, hooks, html, run
55

6-
76
HERE = Path(__file__)
87
DATA_PATH = HERE.parent / "data.json"
98
sculpture_data = json.loads(DATA_PATH.read_text())

docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/list_re_order.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def ArtistList():
88
)
99

1010
def handle_sort_click(event):
11-
set_artists(list(sorted(artists)))
11+
set_artists(sorted(artists))
1212

1313
def handle_reverse_click(event):
1414
set_artists(list(reversed(artists)))

docs/source/guides/creating-interfaces/rendering-data/_examples/sorted_and_filtered_todo_list.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def DataList(items, filter_by_priority=None, sort_by_priority=False):
66
if filter_by_priority is not None:
77
items = [i for i in items if i["priority"] <= filter_by_priority]
88
if sort_by_priority:
9-
items = list(sorted(items, key=lambda i: i["priority"]))
9+
items = sorted(items, key=lambda i: i["priority"])
1010
list_item_elements = [html.li(i["text"]) for i in items]
1111
return html.ul(list_item_elements)
1212

docs/source/guides/creating-interfaces/rendering-data/_examples/todo_list_with_keys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def DataList(items, filter_by_priority=None, sort_by_priority=False):
66
if filter_by_priority is not None:
77
items = [i for i in items if i["priority"] <= filter_by_priority]
88
if sort_by_priority:
9-
items = list(sorted(items, key=lambda i: i["priority"]))
9+
items = sorted(items, key=lambda i: i["priority"])
1010
list_item_elements = [html.li({"key": i["id"]}, i["text"]) for i in items]
1111
return html.ul(list_item_elements)
1212

docs/source/guides/escape-hatches/_examples/material_ui_button_no_action.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from reactpy import component, run, web
22

3-
43
mui = web.module_from_template(
54
"react@^17.0.0",
65
"@material-ui/[email protected]",

docs/source/guides/escape-hatches/_examples/material_ui_button_on_click.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import reactpy
44

5-
65
mui = reactpy.web.module_from_template(
76
"react@^17.0.0",
87
"@material-ui/[email protected]",

docs/source/guides/escape-hatches/_examples/super_simple_chart/main.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from reactpy import component, run, web
44

5-
65
file = Path(__file__).parent / "super-simple-chart.js"
76
ssc = web.module_from_file("super-simple-chart", file, fallback="⌛")
87
SuperSimpleChart = web.export(ssc, "SuperSimpleChart")

docs/source/guides/getting-started/_examples/debug_error_example.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def GoodComponent():
1313

1414
@component
1515
def BadComponent():
16-
raise RuntimeError("This component raised an error")
16+
msg = "This component raised an error"
17+
raise RuntimeError(msg)
1718

1819

1920
run(App)

docs/source/guides/getting-started/_examples/run_fastapi.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from reactpy import run
44
from reactpy.backend import fastapi as fastapi_server
55

6-
76
# the run() function is the entry point for examples
87
fastapi_server.configure = lambda _, cmpt: run(cmpt)
98

docs/source/guides/getting-started/_examples/run_flask.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from reactpy import run
44
from reactpy.backend import flask as flask_server
55

6-
76
# the run() function is the entry point for examples
87
flask_server.configure = lambda _, cmpt: run(cmpt)
98

docs/source/guides/getting-started/_examples/run_sanic.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from reactpy import run
44
from reactpy.backend import sanic as sanic_server
55

6-
76
# the run() function is the entry point for examples
87
sanic_server.configure = lambda _, cmpt: run(cmpt)
98

docs/source/guides/getting-started/_examples/run_starlette.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from reactpy import run
44
from reactpy.backend import starlette as starlette_server
55

6-
76
# the run() function is the entry point for examples
87
starlette_server.configure = lambda _, cmpt: run(cmpt)
98

docs/source/guides/getting-started/_examples/run_tornado.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from reactpy import run
44
from reactpy.backend import tornado as tornado_server
55

6-
76
# the run() function is the entry point for examples
87
tornado_server.configure = lambda _, cmpt: run(cmpt)
98

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import reactpy
22

3-
43
reactpy.run(reactpy.sample.SampleApp)

docs/source/guides/getting-started/_static/embed-reactpy-view/main.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from reactpy import component, html
55
from reactpy.backend.sanic import Options, configure
66

7-
87
app = Sanic("MyApp")
98

109

docs/source/guides/managing-state/sharing-component-state/_examples/filterable_list/main.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from reactpy import component, hooks, html, run
55

6-
76
HERE = Path(__file__)
87
DATA_PATH = HERE.parent / "data.json"
98
food_data = json.loads(DATA_PATH.read_text())
@@ -33,7 +32,7 @@ def Table(value, set_value):
3332
name = html.td(row["name"])
3433
descr = html.td(row["description"])
3534
tr = html.tr(name, descr, value)
36-
if value == "":
35+
if not value:
3736
rows.append(tr)
3837
else:
3938
if value.lower() in row["name"].lower():

docs/source/reference/_examples/character_movement/main.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from reactpy import component, html, run, use_state
55
from reactpy.widgets import image
66

7-
87
HERE = Path(__file__)
98
CHARACTER_IMAGE = (HERE.parent / "static" / "bunny.png").read_bytes()
109

docs/source/reference/_examples/material_ui_switch.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import reactpy
22

3-
43
mui = reactpy.web.module_from_template("react", "@material-ui/core@^5.0", fallback="⌛")
54
Switch = reactpy.web.export(mui, "Switch")
65

0 commit comments

Comments
 (0)