From 0e99ce91c1bef833f06d66c4736f56c0bb7d4df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Mon, 7 Oct 2024 14:52:36 -0700 Subject: [PATCH] update ruff to latest version (#4081) * update ruff to latest version * fix pyi --- .pre-commit-config.yaml | 4 +-- poetry.lock | 39 +++++++++++---------- pyproject.toml | 2 +- reflex/components/datadisplay/dataeditor.py | 2 +- reflex/components/el/__init__.pyi | 1 + reflex/components/tags/iter_tag.py | 4 +-- reflex/utils/compat.py | 4 +-- reflex/utils/telemetry.py | 4 +-- reflex/utils/types.py | 4 +-- reflex/vars/base.py | 2 +- tests/units/components/core/test_cond.py | 2 +- tests/units/components/core/test_foreach.py | 10 +++--- tests/units/components/core/test_match.py | 10 +++--- tests/units/components/test_tag.py | 2 +- tests/units/test_state.py | 8 ++--- tests/units/test_var.py | 4 +-- tests/units/utils/test_utils.py | 4 ++- 17 files changed, 53 insertions(+), 53 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 609364a6e..4d2e76b31 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ fail_fast: true repos: - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.4.10 + rev: v0.6.9 hooks: - id: ruff-format args: [reflex, tests] @@ -25,7 +25,7 @@ repos: rev: v1.1.313 hooks: - id: pyright - args: [integration, reflex, tests] + args: [reflex, tests] language: system - repo: https://github.com/terrencepreilly/darglint diff --git a/poetry.lock b/poetry.lock index 158574222..144547342 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2255,28 +2255,29 @@ jupyter = ["ipywidgets (>=7.5.1,<9)"] [[package]] name = "ruff" -version = "0.4.10" +version = "0.6.9" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.4.10-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:5c2c4d0859305ac5a16310eec40e4e9a9dec5dcdfbe92697acd99624e8638dac"}, - {file = "ruff-0.4.10-py3-none-macosx_11_0_arm64.whl", hash = "sha256:a79489607d1495685cdd911a323a35871abfb7a95d4f98fc6f85e799227ac46e"}, - {file = "ruff-0.4.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b1dd1681dfa90a41b8376a61af05cc4dc5ff32c8f14f5fe20dba9ff5deb80cd6"}, - {file = "ruff-0.4.10-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:c75c53bb79d71310dc79fb69eb4902fba804a81f374bc86a9b117a8d077a1784"}, - {file = "ruff-0.4.10-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:18238c80ee3d9100d3535d8eb15a59c4a0753b45cc55f8bf38f38d6a597b9739"}, - {file = "ruff-0.4.10-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:d8f71885bce242da344989cae08e263de29752f094233f932d4f5cfb4ef36a81"}, - {file = "ruff-0.4.10-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:330421543bd3222cdfec481e8ff3460e8702ed1e58b494cf9d9e4bf90db52b9d"}, - {file = "ruff-0.4.10-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9e9b6fb3a37b772628415b00c4fc892f97954275394ed611056a4b8a2631365e"}, - {file = "ruff-0.4.10-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0f54c481b39a762d48f64d97351048e842861c6662d63ec599f67d515cb417f6"}, - {file = "ruff-0.4.10-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:67fe086b433b965c22de0b4259ddfe6fa541c95bf418499bedb9ad5fb8d1c631"}, - {file = "ruff-0.4.10-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:acfaaab59543382085f9eb51f8e87bac26bf96b164839955f244d07125a982ef"}, - {file = "ruff-0.4.10-py3-none-musllinux_1_2_i686.whl", hash = "sha256:3cea07079962b2941244191569cf3a05541477286f5cafea638cd3aa94b56815"}, - {file = "ruff-0.4.10-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:338a64ef0748f8c3a80d7f05785930f7965d71ca260904a9321d13be24b79695"}, - {file = "ruff-0.4.10-py3-none-win32.whl", hash = "sha256:ffe3cd2f89cb54561c62e5fa20e8f182c0a444934bf430515a4b422f1ab7b7ca"}, - {file = "ruff-0.4.10-py3-none-win_amd64.whl", hash = "sha256:67f67cef43c55ffc8cc59e8e0b97e9e60b4837c8f21e8ab5ffd5d66e196e25f7"}, - {file = "ruff-0.4.10-py3-none-win_arm64.whl", hash = "sha256:dd1fcee327c20addac7916ca4e2653fbbf2e8388d8a6477ce5b4e986b68ae6c0"}, - {file = "ruff-0.4.10.tar.gz", hash = "sha256:3aa4f2bc388a30d346c56524f7cacca85945ba124945fe489952aadb6b5cd804"}, + {file = "ruff-0.6.9-py3-none-linux_armv6l.whl", hash = "sha256:064df58d84ccc0ac0fcd63bc3090b251d90e2a372558c0f057c3f75ed73e1ccd"}, + {file = "ruff-0.6.9-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:140d4b5c9f5fc7a7b074908a78ab8d384dd7f6510402267bc76c37195c02a7ec"}, + {file = "ruff-0.6.9-py3-none-macosx_11_0_arm64.whl", hash = "sha256:53fd8ca5e82bdee8da7f506d7b03a261f24cd43d090ea9db9a1dc59d9313914c"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:645d7d8761f915e48a00d4ecc3686969761df69fb561dd914a773c1a8266e14e"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:eae02b700763e3847595b9d2891488989cac00214da7f845f4bcf2989007d577"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7d5ccc9e58112441de8ad4b29dcb7a86dc25c5f770e3c06a9d57e0e5eba48829"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:417b81aa1c9b60b2f8edc463c58363075412866ae4e2b9ab0f690dc1e87ac1b5"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3c866b631f5fbce896a74a6e4383407ba7507b815ccc52bcedabb6810fdb3ef7"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7b118afbb3202f5911486ad52da86d1d52305b59e7ef2031cea3425142b97d6f"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a67267654edc23c97335586774790cde402fb6bbdb3c2314f1fc087dee320bfa"}, + {file = "ruff-0.6.9-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3ef0cc774b00fec123f635ce5c547dac263f6ee9fb9cc83437c5904183b55ceb"}, + {file = "ruff-0.6.9-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:12edd2af0c60fa61ff31cefb90aef4288ac4d372b4962c2864aeea3a1a2460c0"}, + {file = "ruff-0.6.9-py3-none-musllinux_1_2_i686.whl", hash = "sha256:55bb01caeaf3a60b2b2bba07308a02fca6ab56233302406ed5245180a05c5625"}, + {file = "ruff-0.6.9-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:925d26471fa24b0ce5a6cdfab1bb526fb4159952385f386bdcc643813d472039"}, + {file = "ruff-0.6.9-py3-none-win32.whl", hash = "sha256:eb61ec9bdb2506cffd492e05ac40e5bc6284873aceb605503d8494180d6fc84d"}, + {file = "ruff-0.6.9-py3-none-win_amd64.whl", hash = "sha256:785d31851c1ae91f45b3d8fe23b8ae4b5170089021fbb42402d811135f0b7117"}, + {file = "ruff-0.6.9-py3-none-win_arm64.whl", hash = "sha256:a9641e31476d601f83cd602608739a0840e348bda93fec9f1ee816f8b6798b93"}, + {file = "ruff-0.6.9.tar.gz", hash = "sha256:b076ef717a8e5bc819514ee1d602bbdca5b4420ae13a9cf61a0c0a4f53a2baa2"}, ] [[package]] @@ -3006,4 +3007,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "73182556dcb255bdc74f3ea607b4c04dac29e31b78d8b498220584e5fd2d81f2" +content-hash = "796ddba36f031ad2b47cae43ce6c49102e2cb98f92823b265d9779e6684333f6" diff --git a/pyproject.toml b/pyproject.toml index 9c7395772..17ee4d132 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ darglint = ">=1.8.1,<2.0" toml = ">=0.10.2,<1.0" pytest-asyncio = ">=0.24.0" pytest-cov = ">=4.0.0,<6.0" -ruff = "^0.4.9" +ruff = "^0.6.9" pandas = ">=2.1.1,<3.0" pillow = ">=10.0.0,<11.0" plotly = ">=5.13.0,<6.0" diff --git a/reflex/components/datadisplay/dataeditor.py b/reflex/components/datadisplay/dataeditor.py index f80ad4ec6..1c778f52a 100644 --- a/reflex/components/datadisplay/dataeditor.py +++ b/reflex/components/datadisplay/dataeditor.py @@ -329,7 +329,7 @@ class DataEditor(NoSSRComponent): columns = props.get("columns", []) data = props.get("data", []) - rows = props.get("rows", None) + rows = props.get("rows") # If rows is not provided, determine from data. if rows is None: diff --git a/reflex/components/el/__init__.pyi b/reflex/components/el/__init__.pyi index adf657b7e..4815bcd27 100644 --- a/reflex/components/el/__init__.pyi +++ b/reflex/components/el/__init__.pyi @@ -3,6 +3,7 @@ # This file was generated by `reflex/utils/pyi_generator.py`! # ------------------------------------------------------ +from . import elements as elements from .elements.forms import Button as Button from .elements.forms import Fieldset as Fieldset from .elements.forms import Form as Form diff --git a/reflex/components/tags/iter_tag.py b/reflex/components/tags/iter_tag.py index 86e5a57fc..fec27f3d9 100644 --- a/reflex/components/tags/iter_tag.py +++ b/reflex/components/tags/iter_tag.py @@ -48,10 +48,10 @@ class IterTag(Tag): """ iterable = self.iterable try: - if iterable._var_type.mro()[0] == dict: + if iterable._var_type.mro()[0] is dict: # Arg is a tuple of (key, value). return Tuple[get_args(iterable._var_type)] # type: ignore - elif iterable._var_type.mro()[0] == tuple: + elif iterable._var_type.mro()[0] is tuple: # Arg is a union of any possible values in the tuple. return Union[get_args(iterable._var_type)] # type: ignore else: diff --git a/reflex/utils/compat.py b/reflex/utils/compat.py index b6d198fd4..e63492a6b 100644 --- a/reflex/utils/compat.py +++ b/reflex/utils/compat.py @@ -87,6 +87,4 @@ def sqlmodel_field_has_primary_key(field) -> bool: return True if getattr(field.field_info, "sa_column", None) is None: return False - if getattr(field.field_info.sa_column, "primary_key", None) is True: - return True - return False + return bool(getattr(field.field_info.sa_column, "primary_key", None)) diff --git a/reflex/utils/telemetry.py b/reflex/utils/telemetry.py index af3994ff8..9ae165ea2 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -94,9 +94,7 @@ def _raise_on_missing_project_hash() -> bool: False when compilation should be skipped (i.e. no .web directory is required). Otherwise return True. """ - if should_skip_compile(): - return False - return True + return not should_skip_compile() def _prepare_event(event: str, **kwargs) -> dict: diff --git a/reflex/utils/types.py b/reflex/utils/types.py index 41e1ed49a..6bedf5b61 100644 --- a/reflex/utils/types.py +++ b/reflex/utils/types.py @@ -374,7 +374,7 @@ def get_base_class(cls: GenericType) -> Type: if is_literal(cls): # only literals of the same type are supported. arg_type = type(get_args(cls)[0]) - if not all(type(arg) == arg_type for arg in get_args(cls)): + if not all(type(arg) is arg_type for arg in get_args(cls)): raise TypeError("only literals of the same type are supported") return type(get_args(cls)[0]) @@ -538,7 +538,7 @@ def is_backend_base_variable(name: str, cls: Type) -> bool: if name in cls.__dict__: value = cls.__dict__[name] - if type(value) == classmethod: + if type(value) is classmethod: return False if callable(value): return False diff --git a/reflex/vars/base.py b/reflex/vars/base.py index 7eab62c68..a22fd83f1 100644 --- a/reflex/vars/base.py +++ b/reflex/vars/base.py @@ -239,7 +239,7 @@ class Var(Generic[VAR_TYPE]): **kwargs, ) - if (js_expr := kwargs.get("_js_expr", None)) is not None: + if (js_expr := kwargs.get("_js_expr")) is not None: object.__setattr__(value_with_replaced, "_js_expr", js_expr) return value_with_replaced diff --git a/tests/units/components/core/test_cond.py b/tests/units/components/core/test_cond.py index 87b0572cb..f9bdc7d60 100644 --- a/tests/units/components/core/test_cond.py +++ b/tests/units/components/core/test_cond.py @@ -45,7 +45,7 @@ def test_validate_cond(cond_state: BaseState): Text.create("cond is True"), Text.create("cond is False"), ) - cond_dict = cond_component.render() if type(cond_component) == Fragment else {} + cond_dict = cond_component.render() if type(cond_component) is Fragment else {} assert cond_dict["name"] == "Fragment" [condition] = cond_dict["children"] diff --git a/tests/units/components/core/test_foreach.py b/tests/units/components/core/test_foreach.py index 9914e080d..228165d3e 100644 --- a/tests/units/components/core/test_foreach.py +++ b/tests/units/components/core/test_foreach.py @@ -67,7 +67,7 @@ class ComponentStateTest(ComponentState): def display_color(color): - assert color._var_type == str + assert color._var_type is str return box(text(color)) @@ -106,18 +106,18 @@ def display_nested_color_with_shades_v2(color): def display_color_tuple(color): - assert color._var_type == str + assert color._var_type is str return box(text(color)) def display_colors_set(color): - assert color._var_type == str + assert color._var_type is str return box(text(color)) def display_nested_list_element(element: ArrayVar[List[str]], index: NumberVar[int]): assert element._var_type == List[str] - assert index._var_type == int + assert index._var_type is int return box(text(element[index])) @@ -240,7 +240,7 @@ def test_foreach_render(state_var, render_fn, render_dict): arg_index = rend["arg_index"] assert isinstance(arg_index, Var) assert arg_index._js_expr not in seen_index_vars - assert arg_index._var_type == int + assert arg_index._var_type is int seen_index_vars.add(arg_index._js_expr) diff --git a/tests/units/components/core/test_match.py b/tests/units/components/core/test_match.py index 583bfa1e2..f09e800e5 100644 --- a/tests/units/components/core/test_match.py +++ b/tests/units/components/core/test_match.py @@ -41,15 +41,15 @@ def test_match_components(): assert len(match_cases) == 6 assert match_cases[0][0]._js_expr == "1" - assert match_cases[0][0]._var_type == int + assert match_cases[0][0]._var_type is int first_return_value_render = match_cases[0][1].render() assert first_return_value_render["name"] == "RadixThemesText" assert first_return_value_render["children"][0]["contents"] == '{"first value"}' assert match_cases[1][0]._js_expr == "2" - assert match_cases[1][0]._var_type == int + assert match_cases[1][0]._var_type is int assert match_cases[1][1]._js_expr == "3" - assert match_cases[1][1]._var_type == int + assert match_cases[1][1]._var_type is int second_return_value_render = match_cases[1][2].render() assert second_return_value_render["name"] == "RadixThemesText" assert second_return_value_render["children"][0]["contents"] == '{"second value"}' @@ -61,7 +61,7 @@ def test_match_components(): assert third_return_value_render["children"][0]["contents"] == '{"third value"}' assert match_cases[3][0]._js_expr == '"random"' - assert match_cases[3][0]._var_type == str + assert match_cases[3][0]._var_type is str fourth_return_value_render = match_cases[3][1].render() assert fourth_return_value_render["name"] == "RadixThemesText" assert fourth_return_value_render["children"][0]["contents"] == '{"fourth value"}' @@ -73,7 +73,7 @@ def test_match_components(): assert fifth_return_value_render["children"][0]["contents"] == '{"fifth value"}' assert match_cases[5][0]._js_expr == f"({MatchState.get_name()}.num + 1)" - assert match_cases[5][0]._var_type == int + assert match_cases[5][0]._var_type is int fifth_return_value_render = match_cases[5][1].render() assert fifth_return_value_render["name"] == "RadixThemesText" assert fifth_return_value_render["children"][0]["contents"] == '{"sixth value"}' diff --git a/tests/units/components/test_tag.py b/tests/units/components/test_tag.py index c41246e3f..a69e40b8b 100644 --- a/tests/units/components/test_tag.py +++ b/tests/units/components/test_tag.py @@ -119,7 +119,7 @@ def test_format_cond_tag(): tag_dict["false_value"], ) assert cond._js_expr == "logged_in" - assert cond._var_type == bool + assert cond._var_type is bool assert true_value["name"] == "h1" assert true_value["contents"] == "True content" diff --git a/tests/units/test_state.py b/tests/units/test_state.py index 830cfbafb..38cf65fee 100644 --- a/tests/units/test_state.py +++ b/tests/units/test_state.py @@ -274,9 +274,9 @@ def test_base_class_vars(test_state): assert isinstance(prop, Var) assert prop._js_expr.split(".")[-1] == field - assert cls.num1._var_type == int - assert cls.num2._var_type == float - assert cls.key._var_type == str + assert cls.num1._var_type is int + assert cls.num2._var_type is float + assert cls.key._var_type is str def test_computed_class_var(test_state): @@ -526,7 +526,7 @@ def test_set_class_var(): TestState._set_var(Var(_js_expr="num3", _var_type=int)._var_set_state(TestState)) var = TestState.num3 # type: ignore assert var._js_expr == TestState.get_full_name() + ".num3" - assert var._var_type == int + assert var._var_type is int assert var._var_state == TestState.get_full_name() diff --git a/tests/units/test_var.py b/tests/units/test_var.py index 227b01d85..8f907c24a 100644 --- a/tests/units/test_var.py +++ b/tests/units/test_var.py @@ -490,7 +490,7 @@ def test_var_indexing_str(): # Test that indexing gives a type of Var[str]. assert isinstance(str_var[0], Var) - assert str_var[0]._var_type == str + assert str_var[0]._var_type is str # Test basic indexing. assert str(str_var[0]) == "str.at(0)" @@ -623,7 +623,7 @@ def test_str_var_slicing(): # Test that slicing gives a type of Var[str]. assert isinstance(str_var[:1], Var) - assert str_var[:1]._var_type == str + assert str_var[:1]._var_type is str # Test basic slicing. assert str(str_var[:1]) == 'str.split("").slice(undefined, 1).join("")' diff --git a/tests/units/utils/test_utils.py b/tests/units/utils/test_utils.py index 41bd4e661..81579acc7 100644 --- a/tests/units/utils/test_utils.py +++ b/tests/units/utils/test_utils.py @@ -542,7 +542,9 @@ def test_style_prop_with_event_handler_value(callable): style = { "color": ( - EventHandler(fn=callable) if type(callable) != EventHandler else callable + EventHandler(fn=callable) + if type(callable) is not EventHandler + else callable ) }