Skip to content

Commit 642233b

Browse files
authored
enable UP ruff rule (#5137)
* enable UP ruff rule * fix tests
1 parent 90512dc commit 642233b

File tree

124 files changed

+540
-637
lines changed

Some content is hidden

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

124 files changed

+540
-637
lines changed

pyi_hashes.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
"reflex/components/core/auto_scroll.pyi": "d3012d2a4ccaab8dfebf9aa484020f59",
1717
"reflex/components/core/banner.pyi": "48d0eb86ae09e806ebe20d0edcc3cdb3",
1818
"reflex/components/core/client_side_routing.pyi": "9be638a2b0e00b8181697e5dd6b45e4e",
19-
"reflex/components/core/clipboard.pyi": "af76b623d593df3b16162033c597f920",
20-
"reflex/components/core/debounce.pyi": "76d857eb814bc64625860a5f43e8b230",
19+
"reflex/components/core/clipboard.pyi": "4098368af3c32dbde77fc74599f8799a",
20+
"reflex/components/core/debounce.pyi": "affda049624c266c7d5620efa3b7041b",
2121
"reflex/components/core/html.pyi": "b12117b42ef79ee90b6b4dec50baeb86",
2222
"reflex/components/core/sticky.pyi": "c65131cf7c2312c68e1fddaa0cc27150",
23-
"reflex/components/core/upload.pyi": "16bf18a95d830184a1ae6c177e91e529",
23+
"reflex/components/core/upload.pyi": "53e06193fa23a603737bc49b1c6c2565",
2424
"reflex/components/datadisplay/__init__.pyi": "cf087efa8b3960decc6b231cc986cfa9",
2525
"reflex/components/datadisplay/code.pyi": "3d8f0ab4c2f123d7f80d15c7ebc553d9",
26-
"reflex/components/datadisplay/dataeditor.pyi": "1b762071001161e4fdd1285263c33bb3",
26+
"reflex/components/datadisplay/dataeditor.pyi": "cb03d732e2fe771a8d46c7bcda671f92",
2727
"reflex/components/datadisplay/shiki_code_block.pyi": "87db7639bfa5cd53e1709e1363f93278",
2828
"reflex/components/el/__init__.pyi": "09042a2db5e0637e99b5173430600522",
2929
"reflex/components/el/element.pyi": "06ac2213b062119323291fa66a1ac19e",
3030
"reflex/components/el/elements/__init__.pyi": "280ed457675f3720e34b560a3f617739",
3131
"reflex/components/el/elements/base.pyi": "6e533348b5e1a88cf62fbb5a38dbd795",
32-
"reflex/components/el/elements/forms.pyi": "2e7ab39bc7295b8594f38a2aa59c9610",
32+
"reflex/components/el/elements/forms.pyi": "161f1ef847e5da8755528a7977fdcf53",
3333
"reflex/components/el/elements/inline.pyi": "33d9d860e75dd8c4769825127ed363bb",
3434
"reflex/components/el/elements/media.pyi": "addd6872281d65d44a484358b895432f",
3535
"reflex/components/el/elements/metadata.pyi": "974a86d9f0662f6fc15a5bb4b3a87862",
@@ -38,23 +38,23 @@
3838
"reflex/components/el/elements/sectioning.pyi": "65aa53b1372598ec1785616cb7016032",
3939
"reflex/components/el/elements/tables.pyi": "e1282d8ddf4efa4c911ca104a907ee88",
4040
"reflex/components/el/elements/typography.pyi": "00088c9c1b68a14e5a41d837e8fdf542",
41-
"reflex/components/gridjs/datatable.pyi": "7fd1dd65ba143d60b7d42d1bb90a179d",
41+
"reflex/components/gridjs/datatable.pyi": "3db3f994640c19be5c3fa2983f71de56",
4242
"reflex/components/lucide/icon.pyi": "a5521a8baf8d2d7281e3fdfe6ce7073b",
43-
"reflex/components/markdown/markdown.pyi": "f2d0cbff02e0a26f201287fabe6fb738",
43+
"reflex/components/markdown/markdown.pyi": "6b268afa879e33abf651bda56be5065e",
4444
"reflex/components/moment/moment.pyi": "6dd0c7cee5f0f29bc11d830c697d7f92",
4545
"reflex/components/next/base.pyi": "14aafd5b018a4bc9748a3c9980fcfe3e",
4646
"reflex/components/next/image.pyi": "3a0d1970e69144e9c6806e68ab99f181",
4747
"reflex/components/next/link.pyi": "cd913e10205314afe67101d9640e05cb",
4848
"reflex/components/next/video.pyi": "09698418db651917630a7fefeb573fc2",
49-
"reflex/components/plotly/plotly.pyi": "77afe88b405c3eae7058994d53a27946",
49+
"reflex/components/plotly/plotly.pyi": "b1f0bbcaf4706d0a373c99395ba50118",
5050
"reflex/components/radix/__init__.pyi": "8d586cbff1d7130d09476ac72ee73400",
5151
"reflex/components/radix/primitives/__init__.pyi": "fe8715decf3e9ae471b56bba14e42cb3",
52-
"reflex/components/radix/primitives/accordion.pyi": "b1482766c3c99ab40c2f446598fdb6a7",
52+
"reflex/components/radix/primitives/accordion.pyi": "54427d58c5e1498ad2c6189214bba28a",
5353
"reflex/components/radix/primitives/base.pyi": "8b1dbf0b75cb29e873d611b83c9e4156",
54-
"reflex/components/radix/primitives/drawer.pyi": "b6f8b17e1d0064d5609915546c722a81",
54+
"reflex/components/radix/primitives/drawer.pyi": "95cc7c2fdc5407f8ceca06199d4503fa",
5555
"reflex/components/radix/primitives/form.pyi": "79ddb679e0b3df814439ce993fcf355e",
5656
"reflex/components/radix/primitives/progress.pyi": "c62a0c44e0d440701174fcca93bf8fbe",
57-
"reflex/components/radix/primitives/slider.pyi": "c27e1a1180442e2e6e9d727560e8068c",
57+
"reflex/components/radix/primitives/slider.pyi": "10196fb967c9cde3860a930a526b6c51",
5858
"reflex/components/radix/themes/__init__.pyi": "a15f9464ad99f248249ffa8e6deea4cf",
5959
"reflex/components/radix/themes/base.pyi": "a3c3c3b72fd3d8f1e38990e5c461b682",
6060
"reflex/components/radix/themes/color_mode.pyi": "435a51382eab6111aae1b26e79e9a473",
@@ -68,7 +68,7 @@
6868
"reflex/components/radix/themes/components/card.pyi": "fe42e0cbdf9eb34341f4bbba8a586b34",
6969
"reflex/components/radix/themes/components/checkbox.pyi": "78bc26eabd6468a44f5139449a2c6208",
7070
"reflex/components/radix/themes/components/checkbox_cards.pyi": "cc43c568aa42ffa3e693e5cd1acba156",
71-
"reflex/components/radix/themes/components/checkbox_group.pyi": "e36603b9ea5f161070c5a0235c4411fa",
71+
"reflex/components/radix/themes/components/checkbox_group.pyi": "b798c7cca10f4493484dc1621c0eed9c",
7272
"reflex/components/radix/themes/components/context_menu.pyi": "cdf546723a84c99412d91ca63d4bb2df",
7373
"reflex/components/radix/themes/components/data_list.pyi": "768e4c9222d37d90228309166a1c6ab3",
7474
"reflex/components/radix/themes/components/dialog.pyi": "b51cb34dc6c90ccd07a2f9fc97eaf1c1",
@@ -80,28 +80,28 @@
8080
"reflex/components/radix/themes/components/progress.pyi": "c880c6bb9803d47048f656dfa66a7c15",
8181
"reflex/components/radix/themes/components/radio.pyi": "36fa5585440685a7d2dff40b50502840",
8282
"reflex/components/radix/themes/components/radio_cards.pyi": "e9a0f27119322e6148946ae178edb7a9",
83-
"reflex/components/radix/themes/components/radio_group.pyi": "ea3180940390e4b6eaf10670be5bc2fe",
83+
"reflex/components/radix/themes/components/radio_group.pyi": "510e2ac6aebec248c275f4ddb25940a9",
8484
"reflex/components/radix/themes/components/scroll_area.pyi": "83892be0b2c902d2147cbdb5e19310ab",
85-
"reflex/components/radix/themes/components/segmented_control.pyi": "7be200991becc54cd885465656e2dfef",
86-
"reflex/components/radix/themes/components/select.pyi": "655a5c2182a16121440e5ddbba2079d8",
85+
"reflex/components/radix/themes/components/segmented_control.pyi": "ee1b8cb2cada89459d17a186206f3c3a",
86+
"reflex/components/radix/themes/components/select.pyi": "869d36f7a20b466bc15c634c7c0ee0dd",
8787
"reflex/components/radix/themes/components/separator.pyi": "58a95aca75a556d349eb56f898bde680",
8888
"reflex/components/radix/themes/components/skeleton.pyi": "d91615706e5efb81d97755decbbf5ae3",
89-
"reflex/components/radix/themes/components/slider.pyi": "b87ee08b7edfe41eddf3d3c1cb71124e",
89+
"reflex/components/radix/themes/components/slider.pyi": "8caaea62efdd0b4b9878a63620c97632",
9090
"reflex/components/radix/themes/components/spinner.pyi": "80766a7324b582221edb66ec46da0acb",
9191
"reflex/components/radix/themes/components/switch.pyi": "f8256d2b50d15ab163649cfb05229750",
9292
"reflex/components/radix/themes/components/table.pyi": "560ce8d920e03b450fe6b938f5f0fea0",
9393
"reflex/components/radix/themes/components/tabs.pyi": "96ac1082651d2adc2a60a3af6e90c17f",
9494
"reflex/components/radix/themes/components/text_area.pyi": "418d3df53eeca0723d83a93d81f16b12",
9595
"reflex/components/radix/themes/components/text_field.pyi": "cdf0e08f5af0a5fce6b31787001f1dc3",
96-
"reflex/components/radix/themes/components/tooltip.pyi": "6cd225ba10140e925752c74404336f27",
96+
"reflex/components/radix/themes/components/tooltip.pyi": "c37fb988ec52da25be83083c3a85524a",
9797
"reflex/components/radix/themes/layout/__init__.pyi": "9a52c5b283c864be70b51a8fd6120392",
9898
"reflex/components/radix/themes/layout/base.pyi": "e9a5c1f376e66653ebcf5d2315f990f8",
9999
"reflex/components/radix/themes/layout/box.pyi": "5a3c2339d74cc062358ec32b2c2c138c",
100100
"reflex/components/radix/themes/layout/center.pyi": "29bde2c21a190ba7d7a382a1157f5aa7",
101101
"reflex/components/radix/themes/layout/container.pyi": "4020c3dca660027b84d11cc4198393c4",
102102
"reflex/components/radix/themes/layout/flex.pyi": "f814281a5635ad43dd1df23f8e356c66",
103103
"reflex/components/radix/themes/layout/grid.pyi": "6062188367a2c253f014f916197c963d",
104-
"reflex/components/radix/themes/layout/list.pyi": "804f7a36c103cd7a3e362d40a58e8d39",
104+
"reflex/components/radix/themes/layout/list.pyi": "0e91d3f1c82c9094f328e5b8ecd2f60a",
105105
"reflex/components/radix/themes/layout/section.pyi": "41895910072e023ed0fef6a8ad956046",
106106
"reflex/components/radix/themes/layout/spacer.pyi": "029eb0eaa731bcdff7c496e0437e22b1",
107107
"reflex/components/radix/themes/layout/stack.pyi": "3b0da99b00c826d087ed89fc67c595c1",
@@ -115,12 +115,12 @@
115115
"reflex/components/react_player/react_player.pyi": "63ffffbc24907103f797dcfd85894107",
116116
"reflex/components/react_player/video.pyi": "35ce5ad62e8bff17d9c09d27c362f8dc",
117117
"reflex/components/recharts/__init__.pyi": "a52c9055e37c6ee25ded15688d45e8a5",
118-
"reflex/components/recharts/cartesian.pyi": "34b15e8f5125b5a8145e3e04ed6418e4",
119-
"reflex/components/recharts/charts.pyi": "b3d35de9cea86307ad2ab7d69ff2d06b",
120-
"reflex/components/recharts/general.pyi": "5548fc494c29063c262ca7a7ef51dce8",
121-
"reflex/components/recharts/polar.pyi": "8fb87fd69c9edf55998f11ea8ada76fb",
118+
"reflex/components/recharts/cartesian.pyi": "9dd16c08abe5205c6c414474e2de2f79",
119+
"reflex/components/recharts/charts.pyi": "3570af4627c601d10ee37033f1b2329c",
120+
"reflex/components/recharts/general.pyi": "a1b846d5f2fd0a8b1969b472c5cab2e7",
121+
"reflex/components/recharts/polar.pyi": "973c3e6aa253914c4c5fd18ed32196fb",
122122
"reflex/components/recharts/recharts.pyi": "157acc830323075ffaf4f68d495d1787",
123123
"reflex/components/sonner/toast.pyi": "0b6dc33413f30fdd043b89ec3c8c3f39",
124-
"reflex/components/suneditor/editor.pyi": "284aa914b9bffe840db67ee68192eaf7",
124+
"reflex/components/suneditor/editor.pyi": "7d94c3587f9ee15e4ab68aca8c3a6d8b",
125125
"reflex/experimental/layout.pyi": "6398e779743963ef3e03396696b8ddfb"
126126
}

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ lint.select = [
103103
"SIM",
104104
"T",
105105
"TRY",
106+
"UP",
106107
"W",
107108
]
108109
lint.ignore = [
@@ -115,6 +116,7 @@ lint.ignore = [
115116
"RUF008",
116117
"RUF012",
117118
"TRY0",
119+
"UP038",
118120
]
119121
lint.pydocstyle.convention = "google"
120122

reflex/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ class AdminDash:
1515

1616
models: list = field(default_factory=list)
1717
view_overrides: dict = field(default_factory=dict)
18-
admin: "Admin | None" = None
18+
admin: Admin | None = None

reflex/app.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,12 @@
1313
import json
1414
import sys
1515
import traceback
16+
from collections.abc import AsyncIterator, Callable, Coroutine, MutableMapping
1617
from datetime import datetime
1718
from pathlib import Path
1819
from timeit import default_timer as timer
1920
from types import SimpleNamespace
20-
from typing import (
21-
TYPE_CHECKING,
22-
Any,
23-
AsyncIterator,
24-
BinaryIO,
25-
Callable,
26-
Coroutine,
27-
Dict,
28-
MutableMapping,
29-
Type,
30-
get_args,
31-
get_type_hints,
32-
)
21+
from typing import TYPE_CHECKING, Any, BinaryIO, get_args, get_type_hints
3322

3423
from fastapi import FastAPI, HTTPException, Request
3524
from fastapi import UploadFile as FastAPIUploadFile
@@ -373,13 +362,13 @@ class App(MiddlewareMixin, LifespanMixin):
373362
_pages: dict[str, Component] = dataclasses.field(default_factory=dict)
374363

375364
# A mapping of pages which created states as they were being evaluated.
376-
_stateful_pages: Dict[str, None] = dataclasses.field(default_factory=dict)
365+
_stateful_pages: dict[str, None] = dataclasses.field(default_factory=dict)
377366

378367
# The backend API object.
379368
_api: FastAPI | None = None
380369

381370
# The state class to use for the app.
382-
_state: Type[BaseState] | None = None
371+
_state: type[BaseState] | None = None
383372

384373
# Class to manage many client states.
385374
_state_manager: StateManager | None = None
@@ -1036,7 +1025,7 @@ def _apply_decorated_pages(self):
10361025
for render, kwargs in DECORATED_PAGES[get_config().app_name]:
10371026
self.add_page(render, **kwargs)
10381027

1039-
def _validate_var_dependencies(self, state: Type[BaseState] | None = None) -> None:
1028+
def _validate_var_dependencies(self, state: type[BaseState] | None = None) -> None:
10401029
"""Validate the dependencies of the vars in the app.
10411030
10421031
Args:
@@ -1591,7 +1580,7 @@ def _validate_exception_handlers(self):
15911580

15921581

15931582
async def process(
1594-
app: App, event: Event, sid: str, headers: Dict, client_ip: str
1583+
app: App, event: Event, sid: str, headers: dict, client_ip: str
15951584
) -> AsyncIterator[StateUpdate]:
15961585
"""Process an event.
15971586

reflex/app_mixins/lifespan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import dataclasses
88
import functools
99
import inspect
10-
from typing import Callable, Coroutine
10+
from collections.abc import Callable, Coroutine
1111

1212
from fastapi import FastAPI
1313

reflex/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import TYPE_CHECKING, Any, Type
6+
from typing import TYPE_CHECKING, Any
77

88
import pydantic.v1.main as pydantic_main
99
from pydantic.v1 import BaseModel
1010
from pydantic.v1.fields import ModelField
1111

1212

13-
def validate_field_name(bases: list[Type["BaseModel"]], field_name: str) -> None:
13+
def validate_field_name(bases: list[type[BaseModel]], field_name: str) -> None:
1414
"""Ensure that the field's name does not shadow an existing attribute of the model.
1515
1616
Args:

reflex/compiler/compiler.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
from __future__ import annotations
44

5+
from collections.abc import Iterable, Sequence
56
from datetime import datetime
67
from pathlib import Path
7-
from typing import TYPE_CHECKING, Iterable, Sequence, Type
8+
from typing import TYPE_CHECKING
89

910
from reflex import constants
1011
from reflex.compiler import templates, utils
@@ -97,7 +98,7 @@ def _compile_theme(theme: str) -> str:
9798
return templates.THEME.render(theme=theme)
9899

99100

100-
def _compile_contexts(state: Type[BaseState] | None, theme: Component | None) -> str:
101+
def _compile_contexts(state: type[BaseState] | None, theme: Component | None) -> str:
101102
"""Compile the initial state and contexts.
102103
103104
Args:
@@ -132,7 +133,7 @@ def _compile_contexts(state: Type[BaseState] | None, theme: Component | None) ->
132133

133134
def _compile_page(
134135
component: BaseComponent,
135-
state: Type[BaseState] | None,
136+
state: type[BaseState] | None,
136137
) -> str:
137138
"""Compile the component given the app state.
138139
@@ -516,7 +517,7 @@ def compile_theme(style: ComponentStyle) -> tuple[str, str]:
516517

517518

518519
def compile_contexts(
519-
state: Type[BaseState] | None,
520+
state: type[BaseState] | None,
520521
theme: Component | None,
521522
) -> tuple[str, str]:
522523
"""Compile the initial state / context.
@@ -535,7 +536,7 @@ def compile_contexts(
535536

536537

537538
def compile_page(
538-
path: str, component: BaseComponent, state: Type[BaseState] | None
539+
path: str, component: BaseComponent, state: type[BaseState] | None
539540
) -> tuple[str, str]:
540541
"""Compile a single page.
541542
@@ -739,7 +740,7 @@ def into_component(component: Component | ComponentCallable) -> Component:
739740
def compile_unevaluated_page(
740741
route: str,
741742
page: UnevaluatedPage,
742-
state: Type[BaseState] | None = None,
743+
state: type[BaseState] | None = None,
743744
style: ComponentStyle | None = None,
744745
theme: Component | None = None,
745746
) -> tuple[Component, bool]:
@@ -829,7 +830,7 @@ class ExecutorSafeFunctions:
829830

830831
COMPONENTS: dict[str, BaseComponent] = {}
831832
UNCOMPILED_PAGES: dict[str, UnevaluatedPage] = {}
832-
STATE: Type[BaseState] | None = None
833+
STATE: type[BaseState] | None = None
833834

834835
@classmethod
835836
def compile_page(cls, route: str) -> tuple[str, str]:

reflex/compiler/utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import asyncio
66
import concurrent.futures
77
import traceback
8+
from collections.abc import Sequence
89
from datetime import datetime
910
from pathlib import Path
10-
from typing import Any, Sequence, Type
11+
from typing import Any
1112
from urllib.parse import urlparse
1213

1314
from pydantic.v1.fields import ModelField
@@ -178,7 +179,7 @@ def save_error(error: Exception) -> str:
178179
return str(log_path)
179180

180181

181-
def compile_state(state: Type[BaseState]) -> dict:
182+
def compile_state(state: type[BaseState]) -> dict:
182183
"""Compile the state of the app.
183184
184185
Args:
@@ -211,7 +212,7 @@ def compile_state(state: Type[BaseState]) -> dict:
211212
def _compile_client_storage_field(
212213
field: ModelField,
213214
) -> tuple[
214-
Type[Cookie] | Type[LocalStorage] | Type[SessionStorage] | None,
215+
type[Cookie] | type[LocalStorage] | type[SessionStorage] | None,
215216
dict[str, Any] | None,
216217
]:
217218
"""Compile the given cookie, local_storage or session_storage field.
@@ -234,7 +235,7 @@ def _compile_client_storage_field(
234235

235236

236237
def _compile_client_storage_recursive(
237-
state: Type[BaseState],
238+
state: type[BaseState],
238239
) -> tuple[dict[str, dict], dict[str, dict], dict[str, dict]]:
239240
"""Compile the client-side storage for the given state recursively.
240241
@@ -279,7 +280,7 @@ def _compile_client_storage_recursive(
279280
return cookies, local_storage, session_storage
280281

281282

282-
def compile_client_storage(state: Type[BaseState]) -> dict[str, dict]:
283+
def compile_client_storage(state: type[BaseState]) -> dict[str, dict]:
283284
"""Compile the client-side storage for the given state.
284285
285286
Args:

reflex/components/base/bare.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from __future__ import annotations
44

5-
from typing import Any, Iterator, Sequence
5+
from collections.abc import Iterator, Sequence
6+
from typing import Any
67

78
from reflex.components.component import BaseComponent, Component, ComponentStyle
89
from reflex.components.tags import Tag

0 commit comments

Comments
 (0)