Skip to content

Commit b14c117

Browse files
fix getattr pretty
1 parent e831ed2 commit b14c117

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

python/egglog/pretty.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,8 @@ def _call_inner( # noqa: C901, PLR0911, PLR0912
473473
return f"{slf}[{self(args[0], unwrap_lit=True)}] = {self(args[1], unwrap_lit=True)}"
474474
case _ if method_name in NAMED_UNARY_METHODS:
475475
return NAMED_UNARY_METHODS[method_name], [non_str_slf, *args]
476-
case "__getattr__":
477-
if isinstance(args[0], LitDecl) and isinstance(args[0].value, str):
478-
return f"{slf}.{args[0].value}"
479-
return "getattr", [non_str_slf, *args]
476+
case "__getattr__" if isinstance(args[0], LitDecl) and isinstance(args[0].value, str):
477+
return f"{slf}.{args[0].value}"
480478
case _:
481479
return f"{slf}.{method_name}", args
482480
case ConstantRef(Ident(name)):

python/tests/test_pretty.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def __repr__(self) -> str:
169169
pytest.param(A() >= A(), "A() >= A()", id="greater than or equal"),
170170
pytest.param(A() == A(), "A() == A()", id="equal"),
171171
pytest.param(A() != A(), "A() != A()", id="not equal"),
172-
pytest.param(A().foo, 'getattr(A(), "foo")', id="getattr"),
172+
pytest.param(A().foo, "A().foo", id="getattr"),
173+
pytest.param(A().__getattr__(String("a") + "b"), 'A().__getattr__(join("a", "b"))', id="getattr expr"),
173174
pytest.param(+A(), "+A()", id="pos"),
174175
pytest.param(~A(), "~A()", id="invert"),
175176
pytest.param(round(A()), "round(A())", id="round"),

0 commit comments

Comments
 (0)