Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ruff to latest version #4081

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
39 changes: 20 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion reflex/components/datadisplay/dataeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions reflex/components/el/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions reflex/components/tags/iter_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions reflex/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 1 addition & 3 deletions reflex/utils/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions reflex/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion reflex/vars/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/units/components/core/test_cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
10 changes: 5 additions & 5 deletions tests/units/components/core/test_foreach.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down Expand Up @@ -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]))


Expand Down Expand Up @@ -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)


Expand Down
10 changes: 5 additions & 5 deletions tests/units/components/core/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}'
Expand All @@ -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"}'
Expand All @@ -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"}'
Expand Down
2 changes: 1 addition & 1 deletion tests/units/components/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions tests/units/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions tests/units/test_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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("")'
Expand Down
4 changes: 3 additions & 1 deletion tests/units/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
Loading