diff --git a/python/egglog/egraph.py b/python/egglog/egraph.py index a25411fe..26f7cb39 100644 --- a/python/egglog/egraph.py +++ b/python/egglog/egraph.py @@ -704,8 +704,12 @@ def _fn_decl( # https://docs.astral.sh/ruff/rules/typing-only-standard-library-import/ if "Callable" not in hint_globals: hint_globals["Callable"] = Callable - - hints = get_type_hints(fn, hint_globals, hint_locals) + # Instead of passing both globals and locals, just pass the globals. Otherwise, for some reason forward references + # won't be resolved correctly + # We need this to be false so it returns "__forward_value__" https://github.com/python/cpython/blob/440ed18e08887b958ad50db1b823e692a747b671/Lib/typing.py#L919 + # https://github.com/egraphs-good/egglog-python/issues/210 + hint_globals.update(hint_locals) + hints = get_type_hints(fn, hint_globals) params = list(signature(fn).parameters.values()) diff --git a/python/tests/test_no_import_star.py b/python/tests/test_no_import_star.py new file mode 100644 index 00000000..085f8aa5 --- /dev/null +++ b/python/tests/test_no_import_star.py @@ -0,0 +1,12 @@ +import egglog as el + + +def test_no_import_star(): + """ + https://github.com/egraphs-good/egglog-python/issues/210 + """ + + class Num(el.Expr): + def __init__(self, value: el.i64Like) -> None: ... + + Num(1) # gets an error "NameError: name 'i64' is not defined"