Skip to content

Commit 8b63db0

Browse files
Updates for ruff checks
1 parent 0ad36fc commit 8b63db0

File tree

8 files changed

+24
-45
lines changed

8 files changed

+24
-45
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ repos:
33
- repo: https://github.com/astral-sh/ruff-pre-commit
44
rev: v0.12.7
55
hooks:
6-
- id: ruff
7-
args: [--fix, --exit-non-zero-on-fix]
6+
- id: ruff-check
7+
args: [--fix]
88
- id: ruff-format
99
- repo: https://github.com/astral-sh/uv-pre-commit
10-
# uv version.
11-
rev: 0.8.4
10+
rev: 0.8.5
1211
hooks:
1312
- id: uv-lock

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ ignore = [
199199
# allow blind exception to add context
200200
"BLE001",
201201
# Don't move type checking around so that can be accessed at runtime
202-
"TCH001",
203-
"TCH002",
204-
"TCH003",
202+
"TC001",
203+
"TC002",
204+
"TC003",
205+
# allow eq without hash
206+
"PLW1641",
205207
]
206208
select = ["ALL"]
207209

python/egglog/egraph.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def relation(name: str, /, *tps: type, egg_fn: str | None = None) -> Callable[..
697697

698698

699699
def _relation_decls(name: str, tps: tuple[type, ...], egg_fn: str | None) -> Declarations:
700-
from .builtins import Unit
700+
from .builtins import Unit # noqa: PLC0415
701701

702702
decls = Declarations()
703703
decls |= cast("RuntimeClass", Unit)
@@ -1098,9 +1098,9 @@ def display(self, graphviz: bool = False, **kwargs: Unpack[GraphvizKwargs]) -> N
10981098
10991099
If in IPython it will display it inline, otherwise it will write it to a file and open it.
11001100
"""
1101-
from IPython.display import SVG, display
1101+
from IPython.display import SVG, display # noqa: PLC0415
11021102

1103-
from .visualizer_widget import VisualizerWidget
1103+
from .visualizer_widget import VisualizerWidget # noqa: PLC0415
11041104

11051105
if graphviz:
11061106
if IN_IPYTHON:
@@ -1127,7 +1127,7 @@ def saturate(
11271127
11281128
If an `expr` is passed, it's also extracted after each run and printed
11291129
"""
1130-
from .visualizer_widget import VisualizerWidget
1130+
from .visualizer_widget import VisualizerWidget # noqa: PLC0415
11311131

11321132
def to_json() -> str:
11331133
if expr is not None:
@@ -1619,7 +1619,7 @@ class _NeBuilder(Generic[BASE_EXPR]):
16191619
lhs: BASE_EXPR
16201620

16211621
def to(self, rhs: BASE_EXPR) -> Unit:
1622-
from .builtins import Unit
1622+
from .builtins import Unit # noqa: PLC0415
16231623

16241624
lhs = to_runtime_expr(self.lhs)
16251625
rhs = convert_to_same_type(rhs, lhs)

python/egglog/pretty.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -491,24 +491,3 @@ def _pretty_function_body(self, fn: UnnamedFunctionRef, args: list[ExprDecl]) ->
491491
if arg_names:
492492
prefix += f" {', '.join(self(a.expr) for a in arg_names)}"
493493
return f"{prefix}: {self(res.expr)}"
494-
495-
496-
def _plot_line_length(expr: object): # pragma: no cover
497-
"""
498-
Plots the number of line lengths based on different max lengths
499-
"""
500-
global MAX_LINE_LENGTH, LINE_DIFFERENCE
501-
import altair as alt
502-
import pandas as pd
503-
504-
sizes = []
505-
for line_length in range(40, 180, 10):
506-
MAX_LINE_LENGTH = line_length
507-
for diff in range(0, 40, 5):
508-
LINE_DIFFERENCE = diff
509-
new_l = len(str(expr).split())
510-
sizes.append((line_length, diff, new_l))
511-
512-
df = pd.DataFrame(sizes, columns=["MAX_LINE_LENGTH", "LENGTH_DIFFERENCE", "n"])
513-
514-
return alt.Chart(df).mark_rect().encode(x="MAX_LINE_LENGTH:O", y="LENGTH_DIFFERENCE:O", color="n:Q")

python/egglog/runtime.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def __egg_ref__(self) -> CallableRef:
311311
return self.__egg_ref_thunk__()
312312

313313
def __call__(self, *args: object, _egg_partial_function: bool = False, **kwargs: object) -> RuntimeExpr | None:
314-
from .conversion import resolve_literal
314+
from .conversion import resolve_literal # noqa: PLC0415
315315

316316
if isinstance(self.__egg_bound__, RuntimeExpr):
317317
args = (self.__egg_bound__, *args)
@@ -493,7 +493,7 @@ def __egg_pretty__(self, wrapping_fn: str | None) -> str:
493493
return pretty_decl(self.__egg_decls__, self.__egg_typed_expr__.expr, wrapping_fn=wrapping_fn)
494494

495495
def _ipython_display_(self) -> None:
496-
from IPython.display import Code, display
496+
from IPython.display import Code, display # noqa: PLC0415
497497

498498
display(Code(str(self), language="python"))
499499

@@ -539,7 +539,7 @@ def _special_method(
539539
__name: str = name,
540540
**kwargs: object,
541541
) -> RuntimeExpr | Fact | None:
542-
from .conversion import ConvertError
542+
from .conversion import ConvertError # noqa: PLC0415
543543

544544
class_name = self.__egg_class_name__
545545
class_decl = self.__egg_class_decl__
@@ -566,11 +566,11 @@ def _special_method(
566566
return fn(*args, **kwargs) # type: ignore[arg-type]
567567
# Handle == and != fallbacks to eq and ne helpers if the methods aren't defined on the class explicitly.
568568
if __name == "__eq__":
569-
from .egraph import BaseExpr, eq
569+
from .egraph import BaseExpr, eq # noqa: PLC0415
570570

571571
return eq(cast("BaseExpr", self)).to(cast("BaseExpr", args[0]))
572572
if __name == "__ne__":
573-
from .egraph import BaseExpr, ne
573+
from .egraph import BaseExpr, ne # noqa: PLC0415
574574

575575
return cast("RuntimeExpr", ne(cast("BaseExpr", self)).to(cast("BaseExpr", args[0])))
576576

@@ -591,7 +591,7 @@ def _reflected_method(self: RuntimeExpr, other: object, __non_reflected: str = n
591591

592592

593593
def call_method_min_conversion(slf: object, other: object, name: str) -> RuntimeExpr | None:
594-
from .conversion import min_convertable_tp, resolve_literal
594+
from .conversion import min_convertable_tp, resolve_literal # noqa: PLC0415
595595

596596
# find a minimum type that both can be converted to
597597
# This is so so that calls like `-0.1 * Int("x")` work by upcasting both to floats.

python/egglog/version_compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _collect_type_vars_monkeypatch(types_, typevar_types=None):
3030
3131
_collect_type_vars((T, List[S, T])) == (T, S)
3232
"""
33-
from .runtime import RuntimeClass
33+
from .runtime import RuntimeClass # noqa: PLC0415
3434

3535
if typevar_types is None:
3636
typevar_types = typing.TypeVar
@@ -48,7 +48,7 @@ def _collect_type_vars_monkeypatch(types_, typevar_types=None):
4848
@typing.no_type_check
4949
@typing._tp_cache
5050
def __getitem__monkeypatch(self, params): # noqa: C901, PLR0912
51-
from .runtime import RuntimeClass
51+
from .runtime import RuntimeClass # noqa: PLC0415
5252

5353
if self.__origin__ in (typing.Generic, typing.Protocol):
5454
# Can't subscript Generic[...] or Protocol[...].

python/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import pytest
44
from syrupy.extensions.single_file import SingleFileSnapshotExtension
55

6+
import egglog.conversion
7+
68

79
@pytest.fixture(autouse=True)
810
def _reset_conversions():
9-
import egglog.conversion
10-
1111
old_conversions = copy.copy(egglog.conversion.CONVERSIONS)
1212
old_conversion_decls = copy.copy(egglog.conversion._TO_PROCESS_DECLS)
1313
yield

python/tests/test_unstable_fn.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import ClassVar, TypeAlias
1111

1212
from egglog import *
13+
from egglog.runtime import RuntimeFunction
1314

1415

1516
class Math(Expr):
@@ -167,8 +168,6 @@ def __init__(self) -> None: ...
167168

168169

169170
def test_callable_accepted_as_type():
170-
from egglog.runtime import RuntimeFunction
171-
172171
@function
173172
def func(f: UnstableFn[C, A, B]) -> C: ...
174173

0 commit comments

Comments
 (0)