Skip to content

Commit ac034f4

Browse files
authored
Add ruff rules for Pylint, Refurb, and type hints (#35)
1 parent 750125b commit ac034f4

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
# Ruff version.
4-
rev: v0.15.2
4+
rev: v0.15.4
55
hooks:
66
# Run the linter.
77
- id: ruff-check

pyproject.toml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,20 @@ dev = [
5959
[tool.ruff]
6060
line-length = 99
6161
lint.select = [
62-
# Annotations
63-
"ANN",
64-
# flake8-bugbear
65-
"B",
66-
"D",
67-
# pycodestyle
68-
"E",
69-
# Pyflakes
70-
"F",
71-
# isort
72-
"I",
73-
# Ruff specific
74-
"RUF",
75-
# flake8-simplify
76-
"SIM",
77-
# pyupgrade
78-
"UP",
62+
"ANN", # annotations
63+
"B", # flake8-bugbear
64+
"D", # pydocstyle
65+
"DTZ", # flake8-datetimez
66+
"E", # pycodestyle
67+
"F", # Pyflakes
68+
"FURB", # refurb
69+
"I", # isort
70+
"PL", # Pylint
71+
"PYI", # flake8-pyi
72+
"RUF", # Ruff-specific rules
73+
"SIM", # flake8-simplify
74+
"SLOT", # flake8-slots
75+
"UP", # pyupgrade
7976
]
8077
lint.ignore = [
8178
"D100", # undocumented-public-module
@@ -90,5 +87,6 @@ lint.ignore = [
9087
"D415", # Duplicate of D400
9188
"E501",
9289
]
93-
lint.per-file-ignores."examples/**/*.py" = [ "ANN" ]
90+
lint.per-file-ignores."examples/**/*.py" = [ "ANN", "DTZ005", "PLC0415" ]
9491
lint.fixable = [ "ALL" ]
92+
lint.pylint.allow-magic-value-types = [ "int", "str" ]

src/datastar_py/attributes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ def signals(
127127
:param expressions_: If True, the values of the signals will be evaluated as expressions
128128
rather than literals.
129129
"""
130-
signals = {**(signals_dict if signals_dict else {}), **signals}
130+
signals = {**(signals_dict or {}), **signals}
131131
val = _js_object(signals) if expressions_ else json.dumps(signals)
132132
return SignalsAttr(value=val, alias=self._alias)
133133

134134
def computed(self, computed_dict: Mapping | None = None, /, **computed: str) -> BaseAttr:
135135
"""Create signals that are computed based on an expression."""
136-
computed = {**(computed_dict if computed_dict else {}), **computed}
136+
computed = {**(computed_dict or {}), **computed}
137137
first, *rest = (
138138
BaseAttr("computed", key=sig, value=expr, alias=self._alias)
139139
for sig, expr in computed.items()
@@ -152,7 +152,7 @@ def ignore(self) -> IgnoreAttr:
152152

153153
def attr(self, attr_dict: Mapping | None = None, /, **attrs: str) -> BaseAttr:
154154
"""Set the value of any HTML attributes to expressions, and keep them in sync."""
155-
attrs = {**(attr_dict if attr_dict else {}), **attrs}
155+
attrs = {**(attr_dict or {}), **attrs}
156156
return BaseAttr("attr", value=_js_object(attrs), alias=self._alias)
157157

158158
def bind(self, signal_name: str) -> BaseAttr:
@@ -161,7 +161,7 @@ def bind(self, signal_name: str) -> BaseAttr:
161161

162162
def class_(self, class_dict: Mapping | None = None, /, **classes: str) -> BaseAttr:
163163
"""Add or removes classes to or from an element based on expressions."""
164-
classes = {**(class_dict if class_dict else {}), **classes}
164+
classes = {**(class_dict or {}), **classes}
165165
return BaseAttr("class", value=_js_object(classes), alias=self._alias)
166166

167167
def init(self, expression: str) -> InitAttr:
@@ -216,7 +216,7 @@ def show(self, expression: str) -> BaseAttr:
216216

217217
def style(self, style_dict: Mapping | None = None, /, **styles: str) -> BaseAttr:
218218
"""Set the value of inline CSS styles on an element based on an expression, and keeps them in sync."""
219-
styles = {**(style_dict if style_dict else {}), **styles}
219+
styles = {**(style_dict or {}), **styles}
220220
return BaseAttr("style", value=_js_object(styles), alias=self._alias)
221221

222222
def text(self, expression: str) -> BaseAttr:
@@ -654,7 +654,7 @@ def threshold(self, threshold: int) -> Self:
654654
class OnIntervalAttr(BaseAttr, ViewtransitionMod):
655655
_attr = "on-interval"
656656

657-
def duration(self, duration: int | float | str, *, leading: bool = False) -> Self:
657+
def duration(self, duration: float | str, *, leading: bool = False) -> Self:
658658
"""Set the interval duration."""
659659
self._mods["duration"] = [str(duration)]
660660
if leading:

src/datastar_py/sse.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from itertools import chain
66
from typing import Literal, Protocol, TypeAlias, overload, runtime_checkable
77

8-
import datastar_py.consts as consts
8+
from datastar_py import consts
99
from datastar_py.attributes import _escape
1010

1111
SSE_HEADERS: dict[str, str] = {
@@ -28,7 +28,7 @@ def __html__(self) -> str: ...
2828

2929

3030
class DatastarEvent(str):
31-
pass
31+
__slots__ = ()
3232

3333

3434
# 0..N datastar events
@@ -83,7 +83,7 @@ def patch_elements(
8383
retry_duration: int | None = None,
8484
) -> DatastarEvent: ...
8585
@classmethod
86-
def patch_elements(
86+
def patch_elements( # noqa: PLR0913 too many arguments
8787
cls,
8888
elements: str | _HtmlProvider | None = None,
8989
selector: str | None = None,

0 commit comments

Comments
 (0)