Skip to content

Commit 34b5235

Browse files
Merge origin/main into new-backend
2 parents a898167 + 518ae60 commit 34b5235

18 files changed

+189
-86
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
55

66
version: 2
7+
enable-beta-ecosystems: true
78
updates:
89
- package-ecosystem: "cargo"
910
directory: "/"

.github/workflows/CI.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,24 @@ jobs:
2626
- "3.10"
2727
steps:
2828
- uses: actions/checkout@v4
29-
- uses: astral-sh/setup-uv@v5
29+
- uses: astral-sh/setup-uv@v6
3030
with:
3131
enable-cache: true
32+
python-version: ${{ matrix.py }}
3233
- uses: dtolnay/[email protected]
3334
- uses: Swatinem/rust-cache@v2
34-
- name: Setup python ${{ matrix.py }}
35-
uses: actions/setup-python@v5
36-
with:
37-
python-version: ${{ matrix.py }}
3835
- run: uv sync --extra test --locked
3936
- run: uv run pytest --benchmark-disable -vvv --durations=10
4037

4138
mypy:
4239
runs-on: ubuntu-latest
4340
steps:
4441
- uses: actions/checkout@v4
45-
- uses: astral-sh/setup-uv@v5
42+
- uses: astral-sh/setup-uv@v6
4643
with:
4744
enable-cache: true
4845
- uses: dtolnay/[email protected]
4946
- uses: Swatinem/rust-cache@v2
50-
- uses: actions/setup-python@v5
51-
with:
52-
# Run on oldest Python version to catch more errors
53-
python-version: "3.10"
5447
- run: uv sync --extra test --locked
5548
- run: make mypy
5649
- run: make stubtest
@@ -59,14 +52,11 @@ jobs:
5952
runs-on: ubuntu-latest
6053
steps:
6154
- uses: actions/checkout@v4
62-
- uses: astral-sh/setup-uv@v5
55+
- uses: astral-sh/setup-uv@v6
6356
with:
6457
enable-cache: true
6558
- uses: dtolnay/[email protected]
6659
- uses: Swatinem/rust-cache@v2
67-
- uses: actions/setup-python@v5
68-
with:
69-
python-version-file: ".python-version"
7060
- run: uv sync --extra test --locked
7161
- uses: CodSpeedHQ/action@v3
7262
with:
@@ -78,14 +68,11 @@ jobs:
7868
runs-on: ubuntu-latest
7969
steps:
8070
- uses: actions/checkout@v4
81-
- uses: astral-sh/setup-uv@v5
71+
- uses: astral-sh/setup-uv@v6
8272
with:
8373
enable-cache: true
8474
- uses: dtolnay/[email protected]
8575
- uses: Swatinem/rust-cache@v2
86-
- uses: actions/setup-python@v5
87-
with:
88-
python-version-file: ".python-version"
8976
- name: Install graphviz
9077
run: |
9178
sudo apt-get update

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "egglog_python"
3-
version = "10.0.1"
3+
version = "10.0.2"
44
edition = "2021"
55

66

docs/changelog.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ _This project uses semantic versioning_
44

55
## UNRELEASED
66

7-
- Upgrade egglog which includes new backend. Removes support for egglog experimental including `Rational` since it
8-
is not compatible with new backend yet.
7+
- Upgrade egglog which includes new backend.
8+
9+
## 10.0.2 (2025-06-22)
10+
11+
- Fix using `f64Like` when not importing star (also properly includes removal of `Callable` special case from previous release).
12+
- Fix Python 3.10 compatibility
913

1014
## 10.0.1 (2025-04-06)
1115

1216
- Fix bug on resolving types if not all imported to your module [#286](https://github.com/egraphs-good/egglog-python/pull/286)
13-
- Also stops special casing including `Callable` as a global. So if you previously included this in a `TYPE_CHECKING` block so it wasn
17+
- Also stops special casing including `Callable` as a global. So if you previously included this in a `TYPE_CHECKING` block so it wasn't
1418
available at runtime you will have to move this to a runtime import if used in a type alias.
1519

1620
## 10.0.0 (2025-03-28)

docs/reference/egglog-translation.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ The `function` decorator supports a number of options as well, which can be pass
108108

109109
- `egg_fn`: The name of the function in egglog. By default, this is the same as the Python function name.
110110
- `cost`: The cost of the function. By default, this is 1.
111-
- `default`: A default value for the function. This must be the same type as the return type of the function.
112111
- `merge`: A function to merge the results of the function. This must be a function that takes two arguments of the return type, the old and the new, and returns a single value of the return type.
113-
- `on_merge`: A function to call when the function is merged. This must be a function that takes two arguments of the return type, the old and the new, and a number of actions to take.
114112

115113
```{code-cell} python
116-
# egg: (function foo () i64 :cost 10 :default 0 :merge (max old new))
117-
@function(egg_fn="foo", default=i64(0), cost=10, merge=lambda old, new: old.max(new))
114+
# egg: (function foo () i64 :cost 10 :merge (max old new))
115+
@function(egg_fn="foo", cost=10, merge=lambda old, new: old.max(new))
118116
def my_foo() -> i64:
119117
pass
120118
```

docs/reference/python-integration.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ If you want to have this work with the static type checker, you can define your
157157
the `Expr` class as the first item in the union. For example, in this case you could then define:
158158

159159
```{code-cell} python
160-
from typing import Union
161-
MathLike = Union[Math, i64Like, StringLike]
160+
MathLike = Math | i64Like | StringLike
162161
163162
@function
164163
def some_math_fn(x: MathLike) -> MathLike:

python/egglog/builtins.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from fractions import Fraction
1010
from functools import partial, reduce
1111
from types import FunctionType, MethodType
12-
from typing import TYPE_CHECKING, Generic, Protocol, TypeAlias, TypeVar, Union, cast, overload
12+
from typing import TYPE_CHECKING, Generic, Protocol, TypeAlias, TypeVar, cast, overload
1313

1414
from typing_extensions import TypeVarTuple, Unpack
1515

@@ -100,8 +100,6 @@ def join(*strings: StringLike) -> String: ...
100100

101101
converter(str, String, String)
102102

103-
BoolLike: TypeAlias = Union["Bool", bool]
104-
105103

106104
class Bool(BuiltinExpr, egg_sort="bool"):
107105
@method(preserve=True)
@@ -132,10 +130,10 @@ def __xor__(self, other: BoolLike) -> Bool: ...
132130
def implies(self, other: BoolLike) -> Bool: ...
133131

134132

135-
converter(bool, Bool, Bool)
133+
BoolLike: TypeAlias = Bool | bool
136134

137-
# The types which can be convertered into an i64
138-
i64Like: TypeAlias = Union["i64", int] # noqa: N816, PYI042
135+
136+
converter(bool, Bool, Bool)
139137

140138

141139
class i64(BuiltinExpr): # noqa: N801
@@ -247,16 +245,16 @@ def bool_le(self, other: i64Like) -> Bool: ...
247245
def bool_ge(self, other: i64Like) -> Bool: ...
248246

249247

248+
# The types which can be convertered into an i64
249+
i64Like: TypeAlias = i64 | int # noqa: N816, PYI042
250+
250251
converter(int, i64, i64)
251252

252253

253254
@function(builtin=True, egg_fn="count-matches")
254255
def count_matches(s: StringLike, pattern: StringLike) -> i64: ...
255256

256257

257-
f64Like: TypeAlias = Union["f64", float] # noqa: N816, PYI042
258-
259-
260258
class f64(BuiltinExpr): # noqa: N801
261259
@method(preserve=True)
262260
def eval(self) -> float:
@@ -336,6 +334,9 @@ def from_i64(cls, i: i64) -> f64: ...
336334
def to_string(self) -> String: ...
337335

338336

337+
f64Like: TypeAlias = f64 | float # noqa: N816, PYI042
338+
339+
339340
converter(float, f64, f64)
340341

341342

python/egglog/declarations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __egg_decls__(self) -> Declarations:
9393
# Catch attribute error, so that it isn't bubbled up as a missing attribute and fallbacks on `__getattr__`
9494
# instead raise explicitly
9595
except AttributeError as err:
96-
msg = f"Cannot resolve declerations for {self}"
96+
msg = f"Cannot resolve declarations for {self}"
9797
raise RuntimeError(msg) from err
9898

9999

@@ -308,11 +308,11 @@ class ClassTypeVarRef:
308308
module: str
309309

310310
def to_just(self) -> JustTypeRef:
311-
msg = "egglog does not support generic classes yet."
311+
msg = f"{self}: egglog does not support generic classes yet."
312312
raise NotImplementedError(msg)
313313

314314
def __str__(self) -> str:
315-
return f"{self.module}.{self.name}"
315+
return str(self.to_type_var())
316316

317317
@classmethod
318318
def from_type_var(cls, typevar: TypeVar) -> ClassTypeVarRef:

python/egglog/egraph.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
ClassVar,
1717
Generic,
1818
Literal,
19-
Never,
2019
TypeAlias,
2120
TypedDict,
2221
TypeVar,
@@ -26,7 +25,7 @@
2625
)
2726

2827
import graphviz
29-
from typing_extensions import ParamSpec, Self, Unpack, assert_never
28+
from typing_extensions import Never, ParamSpec, Self, Unpack, assert_never
3029

3130
from . import bindings
3231
from .conversion import *
@@ -36,6 +35,7 @@
3635
from .pretty import pretty_decl
3736
from .runtime import *
3837
from .thunk import *
38+
from .version_compat import *
3939

4040
if TYPE_CHECKING:
4141
from .builtins import String, Unit
@@ -169,8 +169,9 @@ def check_eq(x: BASE_EXPR, y: BASE_EXPR, schedule: Schedule | None = None, *, ad
169169
except bindings.EggSmolError as err:
170170
if display:
171171
egraph.display()
172-
err.add_note(f"Failed:\n{eq(x).to(y)}\n\nExtracted:\n {eq(egraph.extract(x)).to(egraph.extract(y))})")
173-
raise
172+
raise add_note(
173+
f"Failed:\n{eq(x).to(y)}\n\nExtracted:\n {eq(egraph.extract(x)).to(egraph.extract(y))})", err
174+
) from None
174175
return egraph
175176

176177

@@ -492,8 +493,7 @@ def _generate_class_decls( # noqa: C901,PLR0912
492493
reverse_args=reverse_args,
493494
)
494495
except Exception as e:
495-
e.add_note(f"Error processing {cls_name}.{method_name}")
496-
raise
496+
raise add_note(f"Error processing {cls_name}.{method_name}", e) from None
497497

498498
if not builtin and not isinstance(ref, InitRef) and not mutates:
499499
add_default_funcs.append(add_rewrite)
@@ -569,16 +569,11 @@ def _fn_decl(
569569
if not isinstance(fn, FunctionType):
570570
raise NotImplementedError(f"Can only generate function decls for functions not {fn} {type(fn)}")
571571

572-
hint_globals = fn.__globals__.copy()
573-
# Copy Callable into global if not present bc sometimes it gets automatically removed by ruff to type only block
574-
# https://docs.astral.sh/ruff/rules/typing-only-standard-library-import/
575-
if "Callable" not in hint_globals:
576-
hint_globals["Callable"] = Callable
577572
# Instead of passing both globals and locals, just pass the globals. Otherwise, for some reason forward references
578573
# won't be resolved correctly
579574
# We need this to be false so it returns "__forward_value__" https://github.com/python/cpython/blob/440ed18e08887b958ad50db1b823e692a747b671/Lib/typing.py#L919
580575
# https://github.com/egraphs-good/egglog-python/issues/210
581-
hint_globals.update(hint_locals)
576+
hint_globals = {**fn.__globals__, **hint_locals}
582577
hints = get_type_hints(fn, hint_globals)
583578

584579
params = list(signature(fn).parameters.values())
@@ -632,7 +627,7 @@ def _fn_decl(
632627
)
633628
decls |= merged
634629

635-
# defer this in generator so it doesnt resolve for builtins eagerly
630+
# defer this in generator so it doesn't resolve for builtins eagerly
636631
args = (TypedExprDecl(tp.to_just(), VarDecl(name, False)) for name, tp in zip(arg_names, arg_types, strict=True))
637632
res_ref: FunctionRef | MethodRef | ClassMethodRef | PropertyRef | InitRef | UnnamedFunctionRef
638633
res_thunk: Callable[[], object]
@@ -676,7 +671,7 @@ def _fn_decl(
676671
)
677672
res_ref = ref
678673
decls.set_function_decl(ref, decl)
679-
res_thunk = Thunk.fn(_create_default_value, decls, ref, fn, args, ruleset)
674+
res_thunk = Thunk.fn(_create_default_value, decls, ref, fn, args, ruleset, context=f"creating {ref}")
680675
return res_ref, Thunk.fn(_add_default_rewrite_function, decls, res_ref, return_type, ruleset, res_thunk, subsume)
681676

682677

@@ -1045,8 +1040,7 @@ def _run_extract(self, expr: RuntimeExpr, n: int) -> bindings._ExtractReport:
10451040
bindings.ActionCommand(bindings.Extract(span(2), expr, bindings.Lit(span(2), bindings.Int(n))))
10461041
)
10471042
except BaseException as e:
1048-
e.add_note("Extracting: " + str(expr))
1049-
raise
1043+
raise add_note("Extracting: " + str(expr), e) # noqa: B904
10501044
extract_report = self._egraph.extract_report()
10511045
if not extract_report:
10521046
msg = "No extract report saved"

0 commit comments

Comments
 (0)