Skip to content

[pre-commit.ci] pre-commit autoupdate #290

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

Merged
merged 4 commits into from
Aug 7, 2025
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
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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-check
args: [--fix]
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.6.11
rev: 0.8.5
hooks:
- id: uv-lock
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion python/egglog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions python/egglog/egraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,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)
Expand Down Expand Up @@ -1086,9 +1086,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:
Expand All @@ -1115,7 +1115,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:
Expand Down Expand Up @@ -1608,7 +1608,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)
Expand Down
21 changes: 0 additions & 21 deletions python/egglog/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
10 changes: 5 additions & 5 deletions python/egglog/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,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)
Expand Down Expand Up @@ -540,7 +540,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"))

Expand Down Expand Up @@ -577,15 +577,15 @@ 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))

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))

Expand Down Expand Up @@ -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: (
Expand Down
4 changes: 2 additions & 2 deletions python/egglog/version_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[...].
Expand Down
4 changes: 2 additions & 2 deletions python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions python/tests/test_unstable_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import ClassVar, TypeAlias

from egglog import *
from egglog.runtime import RuntimeFunction


class Math(Expr):
Expand Down Expand Up @@ -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: ...

Expand Down
Loading