Skip to content

Commit f42b2dd

Browse files
Add error message if @method decorate is in wrong place
1 parent 9bb83d4 commit f42b2dd

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ _This project uses semantic versioning_
77
- Fix pretty printing of lambda functions
88
- Add support for subsuming rewrite generated by default function and method definitions
99
- Add better error message when using @function in class (thanks @shinawy)
10+
- Add error method if `@method` decorator is in wrong place
1011

1112
## 8.0.1 (2024-10-24)
1213

python/egglog/egraph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ def _generate_class_decls( # noqa: C901,PLR0912
570570
fn = fn.fget
571571
case _:
572572
ref = InitRef(cls_name) if is_init else MethodRef(cls_name, method_name)
573+
if isinstance(fn, _WrappedMethod):
574+
msg = f"{cls_name}.{method_name} Add the @method(...) decorator above @classmethod or @property"
575+
576+
raise ValueError(msg) # noqa: TRY004
573577
special_function_name: SpecialFunctions | None = (
574578
"fn-partial" if egg_fn == "unstable-fn" else "fn-app" if egg_fn == "unstable-app" else None
575579
)

python/egglog/exp/array_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,13 @@ def var(cls, name: StringLike) -> TupleTupleInt: ...
386386

387387
def __init__(self, length: IntLike, idx_fn: Callable[[Int], TupleInt]) -> None: ...
388388

389-
@classmethod
390389
@method(subsume=True)
390+
@classmethod
391391
def single(cls, i: TupleInt) -> TupleTupleInt:
392392
return TupleTupleInt(Int(1), lambda _: i)
393393

394-
@classmethod
395394
@method(subsume=True)
395+
@classmethod
396396
def from_vec(cls, vec: Vec[Int]) -> TupleInt:
397397
return TupleInt(vec.length(), partial(index_vec_int, vec))
398398

0 commit comments

Comments
 (0)