From 3f9b30b2af4efed5a597d9bd3c632e722630b996 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Mon, 7 Oct 2024 12:28:43 +0200 Subject: [PATCH 1/2] update ruff to latest version --- .pre-commit-config.yaml | 4 ++-- pyproject.toml | 2 +- reflex/components/datadisplay/dataeditor.py | 2 +- 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 +++- 15 files changed, 32 insertions(+), 34 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 609364a6e4..4d2e76b310 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/pyproject.toml b/pyproject.toml index 2817413687..63ae95c681 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.20.1,<0.22.0" # https://github.com/pytest-dev/pytest-asyncio/issues/706 pytest-cov = ">=4.0.0,<5.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 9d1ecc7756..01f0329d49 100644 --- a/reflex/components/datadisplay/dataeditor.py +++ b/reflex/components/datadisplay/dataeditor.py @@ -329,7 +329,7 @@ def create(cls, *children, **props) -> Component: 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/tags/iter_tag.py b/reflex/components/tags/iter_tag.py index 86e5a57fc8..fec27f3d90 100644 --- a/reflex/components/tags/iter_tag.py +++ b/reflex/components/tags/iter_tag.py @@ -48,10 +48,10 @@ def get_iterable_var_type(self) -> Type: """ 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 27c4753dbc..be5b1584ef 100644 --- a/reflex/utils/compat.py +++ b/reflex/utils/compat.py @@ -84,6 +84,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 af3994ff80..9ae165ea2f 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 41e1ed49a9..6bedf5b61d 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 0f8a80f8d6..525128eabd 100644 --- a/reflex/vars/base.py +++ b/reflex/vars/base.py @@ -239,7 +239,7 @@ def _replace( **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 f5b6c0895f..a488ccb8aa 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 43b9d8d554..2ad0d852c5 100644 --- a/tests/units/components/core/test_foreach.py +++ b/tests/units/components/core/test_foreach.py @@ -67,7 +67,7 @@ def get_component(cls, *children, **props) -> Component: 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 583bfa1e29..f09e800e53 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 c41246e3fd..a69e40b8b3 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 5bfac76282..b91a945450 100644 --- a/tests/units/test_state.py +++ b/tests/units/test_state.py @@ -273,9 +273,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): @@ -525,7 +525,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 227b01d85e..8f907c24ac 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 41bd4e661f..81579acc77 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 ) } From c38d3214ebd46bdea66c12f3d456625e3907da79 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Mon, 7 Oct 2024 21:20:08 +0200 Subject: [PATCH 2/2] fix pyi --- reflex/components/el/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/reflex/components/el/__init__.pyi b/reflex/components/el/__init__.pyi index adf657b7e0..4815bcd279 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