From 0ad36fc00cc45f1f0c7e2af23edead847a748762 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Aug 2025 20:15:31 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.11.2 → v0.12.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.11.2...v0.12.7) - [github.com/astral-sh/uv-pre-commit: 0.6.11 → 0.8.4](https://github.com/astral-sh/uv-pre-commit/compare/0.6.11...0.8.4) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b533de5c..f321c81f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ exclude: ^python/tests/__snapshots__/ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.2 + rev: v0.12.7 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - repo: https://github.com/astral-sh/uv-pre-commit # uv version. - rev: 0.6.11 + rev: 0.8.4 hooks: - id: uv-lock From 8b63db0bae5bb63409bdb388900f8ff26a95c294 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Thu, 7 Aug 2025 10:42:03 -0400 Subject: [PATCH 2/3] Updates for ruff checks --- .pre-commit-config.yaml | 7 +++---- pyproject.toml | 8 +++++--- python/egglog/egraph.py | 10 +++++----- python/egglog/pretty.py | 21 --------------------- python/egglog/runtime.py | 12 ++++++------ python/egglog/version_compat.py | 4 ++-- python/tests/conftest.py | 4 ++-- python/tests/test_unstable_fn.py | 3 +-- 8 files changed, 24 insertions(+), 45 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f321c81f..ae023079 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,11 +3,10 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.12.7 hooks: - - id: ruff - args: [--fix, --exit-non-zero-on-fix] + - id: ruff-check + args: [--fix] - id: ruff-format - repo: https://github.com/astral-sh/uv-pre-commit - # uv version. - rev: 0.8.4 + rev: 0.8.5 hooks: - id: uv-lock diff --git a/pyproject.toml b/pyproject.toml index 9e3f0403..ac8c3894 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -199,9 +199,11 @@ ignore = [ # allow blind exception to add context "BLE001", # Don't move type checking around so that can be accessed at runtime - "TCH001", - "TCH002", - "TCH003", + "TC001", + "TC002", + "TC003", + # allow eq without hash + "PLW1641", ] select = ["ALL"] diff --git a/python/egglog/egraph.py b/python/egglog/egraph.py index 520baeaa..201e840d 100644 --- a/python/egglog/egraph.py +++ b/python/egglog/egraph.py @@ -697,7 +697,7 @@ def relation(name: str, /, *tps: type, egg_fn: str | None = None) -> Callable[.. def _relation_decls(name: str, tps: tuple[type, ...], egg_fn: str | None) -> Declarations: - from .builtins import Unit + from .builtins import Unit # noqa: PLC0415 decls = Declarations() decls |= cast("RuntimeClass", Unit) @@ -1098,9 +1098,9 @@ def display(self, graphviz: bool = False, **kwargs: Unpack[GraphvizKwargs]) -> N If in IPython it will display it inline, otherwise it will write it to a file and open it. """ - from IPython.display import SVG, display + from IPython.display import SVG, display # noqa: PLC0415 - from .visualizer_widget import VisualizerWidget + from .visualizer_widget import VisualizerWidget # noqa: PLC0415 if graphviz: if IN_IPYTHON: @@ -1127,7 +1127,7 @@ def saturate( If an `expr` is passed, it's also extracted after each run and printed """ - from .visualizer_widget import VisualizerWidget + from .visualizer_widget import VisualizerWidget # noqa: PLC0415 def to_json() -> str: if expr is not None: @@ -1619,7 +1619,7 @@ class _NeBuilder(Generic[BASE_EXPR]): lhs: BASE_EXPR def to(self, rhs: BASE_EXPR) -> Unit: - from .builtins import Unit + from .builtins import Unit # noqa: PLC0415 lhs = to_runtime_expr(self.lhs) rhs = convert_to_same_type(rhs, lhs) diff --git a/python/egglog/pretty.py b/python/egglog/pretty.py index 41659074..01beddc5 100644 --- a/python/egglog/pretty.py +++ b/python/egglog/pretty.py @@ -491,24 +491,3 @@ def _pretty_function_body(self, fn: UnnamedFunctionRef, args: list[ExprDecl]) -> if arg_names: prefix += f" {', '.join(self(a.expr) for a in arg_names)}" return f"{prefix}: {self(res.expr)}" - - -def _plot_line_length(expr: object): # pragma: no cover - """ - Plots the number of line lengths based on different max lengths - """ - global MAX_LINE_LENGTH, LINE_DIFFERENCE - import altair as alt - import pandas as pd - - sizes = [] - for line_length in range(40, 180, 10): - MAX_LINE_LENGTH = line_length - for diff in range(0, 40, 5): - LINE_DIFFERENCE = diff - new_l = len(str(expr).split()) - sizes.append((line_length, diff, new_l)) - - df = pd.DataFrame(sizes, columns=["MAX_LINE_LENGTH", "LENGTH_DIFFERENCE", "n"]) - - return alt.Chart(df).mark_rect().encode(x="MAX_LINE_LENGTH:O", y="LENGTH_DIFFERENCE:O", color="n:Q") diff --git a/python/egglog/runtime.py b/python/egglog/runtime.py index 1963def9..4ea0d18a 100644 --- a/python/egglog/runtime.py +++ b/python/egglog/runtime.py @@ -311,7 +311,7 @@ def __egg_ref__(self) -> CallableRef: return self.__egg_ref_thunk__() def __call__(self, *args: object, _egg_partial_function: bool = False, **kwargs: object) -> RuntimeExpr | None: - from .conversion import resolve_literal + from .conversion import resolve_literal # noqa: PLC0415 if isinstance(self.__egg_bound__, RuntimeExpr): args = (self.__egg_bound__, *args) @@ -493,7 +493,7 @@ def __egg_pretty__(self, wrapping_fn: str | None) -> str: return pretty_decl(self.__egg_decls__, self.__egg_typed_expr__.expr, wrapping_fn=wrapping_fn) def _ipython_display_(self) -> None: - from IPython.display import Code, display + from IPython.display import Code, display # noqa: PLC0415 display(Code(str(self), language="python")) @@ -539,7 +539,7 @@ def _special_method( __name: str = name, **kwargs: object, ) -> RuntimeExpr | Fact | None: - from .conversion import ConvertError + from .conversion import ConvertError # noqa: PLC0415 class_name = self.__egg_class_name__ class_decl = self.__egg_class_decl__ @@ -566,11 +566,11 @@ def _special_method( return fn(*args, **kwargs) # type: ignore[arg-type] # Handle == and != fallbacks to eq and ne helpers if the methods aren't defined on the class explicitly. if __name == "__eq__": - from .egraph import BaseExpr, eq + from .egraph import BaseExpr, eq # noqa: PLC0415 return eq(cast("BaseExpr", self)).to(cast("BaseExpr", args[0])) if __name == "__ne__": - from .egraph import BaseExpr, ne + from .egraph import BaseExpr, ne # noqa: PLC0415 return cast("RuntimeExpr", ne(cast("BaseExpr", self)).to(cast("BaseExpr", args[0]))) @@ -591,7 +591,7 @@ def _reflected_method(self: RuntimeExpr, other: object, __non_reflected: str = n def call_method_min_conversion(slf: object, other: object, name: str) -> RuntimeExpr | None: - from .conversion import min_convertable_tp, resolve_literal + from .conversion import min_convertable_tp, resolve_literal # noqa: PLC0415 # find a minimum type that both can be converted to # This is so so that calls like `-0.1 * Int("x")` work by upcasting both to floats. diff --git a/python/egglog/version_compat.py b/python/egglog/version_compat.py index 352b2655..e29f4932 100644 --- a/python/egglog/version_compat.py +++ b/python/egglog/version_compat.py @@ -30,7 +30,7 @@ def _collect_type_vars_monkeypatch(types_, typevar_types=None): _collect_type_vars((T, List[S, T])) == (T, S) """ - from .runtime import RuntimeClass + from .runtime import RuntimeClass # noqa: PLC0415 if typevar_types is None: typevar_types = typing.TypeVar @@ -48,7 +48,7 @@ def _collect_type_vars_monkeypatch(types_, typevar_types=None): @typing.no_type_check @typing._tp_cache def __getitem__monkeypatch(self, params): # noqa: C901, PLR0912 - from .runtime import RuntimeClass + from .runtime import RuntimeClass # noqa: PLC0415 if self.__origin__ in (typing.Generic, typing.Protocol): # Can't subscript Generic[...] or Protocol[...]. diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 73aed445..5ca02195 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -3,11 +3,11 @@ import pytest from syrupy.extensions.single_file import SingleFileSnapshotExtension +import egglog.conversion + @pytest.fixture(autouse=True) def _reset_conversions(): - import egglog.conversion - old_conversions = copy.copy(egglog.conversion.CONVERSIONS) old_conversion_decls = copy.copy(egglog.conversion._TO_PROCESS_DECLS) yield diff --git a/python/tests/test_unstable_fn.py b/python/tests/test_unstable_fn.py index 1a7742cd..eaaab64b 100644 --- a/python/tests/test_unstable_fn.py +++ b/python/tests/test_unstable_fn.py @@ -10,6 +10,7 @@ from typing import ClassVar, TypeAlias from egglog import * +from egglog.runtime import RuntimeFunction class Math(Expr): @@ -167,8 +168,6 @@ def __init__(self) -> None: ... def test_callable_accepted_as_type(): - from egglog.runtime import RuntimeFunction - @function def func(f: UnstableFn[C, A, B]) -> C: ... From 8d5904afc87c22f029fde5f229491c84aac35162 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Thu, 7 Aug 2025 10:47:09 -0400 Subject: [PATCH 3/3] Fix merge conflicts --- python/egglog/__init__.py | 2 +- python/egglog/runtime.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/egglog/__init__.py b/python/egglog/__init__.py index af64575d..6a6e2213 100644 --- a/python/egglog/__init__.py +++ b/python/egglog/__init__.py @@ -8,6 +8,6 @@ from .conversion import * from .deconstruct import * from .egraph import * -from .runtime import define_expr_method as define_expr_method # noqa: PLC0414 +from .runtime import define_expr_method as define_expr_method del ipython_magic diff --git a/python/egglog/runtime.py b/python/egglog/runtime.py index 4103d668..26f8d9fa 100644 --- a/python/egglog/runtime.py +++ b/python/egglog/runtime.py @@ -577,7 +577,7 @@ def __eq__(self, other: object) -> object: # type: ignore[override] # TODO: Check if two objects can be upcasted to be the same. If not, then return NotImplemented so other # expr gets a chance to resolve __eq__ which could be a preserved method. - from .egraph import BaseExpr, eq + from .egraph import BaseExpr, eq # noqa: PLC0415 return eq(cast("BaseExpr", self)).to(cast("BaseExpr", other)) @@ -585,7 +585,7 @@ def __ne__(self, other: object) -> object: # type: ignore[override] if (method := _get_expr_method(self, "__ne__")) is not None: return method(other) - from .egraph import BaseExpr, ne + from .egraph import BaseExpr, ne # noqa: PLC0415 return ne(cast("BaseExpr", self)).to(cast("BaseExpr", other)) @@ -647,7 +647,7 @@ def _numeric_binary_method(self: object, other: object, name: str = name, r_meth ) ) ): - from .conversion import CONVERSIONS, resolve_type, retrieve_conversion_decls + from .conversion import CONVERSIONS, resolve_type, retrieve_conversion_decls # noqa: PLC0415 # tuple of (cost, convert_self) best_method: (