Skip to content

Commit 97a55a2

Browse files
Merge pull request #222 from egraphs-good/no-import-star
Fix usage when not importing all from egglog
2 parents d9f26ff + 59d5380 commit 97a55a2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

python/egglog/egraph.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,12 @@ def _fn_decl(
704704
# https://docs.astral.sh/ruff/rules/typing-only-standard-library-import/
705705
if "Callable" not in hint_globals:
706706
hint_globals["Callable"] = Callable
707-
708-
hints = get_type_hints(fn, hint_globals, hint_locals)
707+
# Instead of passing both globals and locals, just pass the globals. Otherwise, for some reason forward references
708+
# won't be resolved correctly
709+
# We need this to be false so it returns "__forward_value__" https://github.com/python/cpython/blob/440ed18e08887b958ad50db1b823e692a747b671/Lib/typing.py#L919
710+
# https://github.com/egraphs-good/egglog-python/issues/210
711+
hint_globals.update(hint_locals)
712+
hints = get_type_hints(fn, hint_globals)
709713

710714
params = list(signature(fn).parameters.values())
711715

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import egglog as el
2+
3+
4+
def test_no_import_star():
5+
"""
6+
https://github.com/egraphs-good/egglog-python/issues/210
7+
"""
8+
9+
class Num(el.Expr):
10+
def __init__(self, value: el.i64Like) -> None: ...
11+
12+
Num(1) # gets an error "NameError: name 'i64' is not defined"

0 commit comments

Comments
 (0)