Skip to content

Commit 4a069e5

Browse files
author
Sylvain MARIE
committed
Fixed NameError in case of unknown symbols in type hints. Fixes #37
1 parent 5356f6e commit 4a069e5

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

makefun/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ def _signature_symbol_needs_protection(symbol, evaldict):
310310
try:
311311
deflt = eval(repr(symbol), evaldict)
312312
needs_protection = deflt != symbol
313+
except NameError:
314+
needs_protection = True
313315
except SyntaxError:
314316
needs_protection = True
315317
else:

makefun/tests/_test_py35.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ def ref(a: A) -> A:
2222
pass
2323

2424
return ref
25+
26+
27+
def make_ref_function2():
28+
""" """
29+
from typing import Any
30+
31+
def ref(a: Any):
32+
pass
33+
34+
return ref

makefun/tests/test_advanced.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,17 @@ def foo(a):
141141
return a
142142

143143
assert foo(10) == 10
144+
145+
146+
@pytest.mark.skipif(sys.version_info < (3, 5), reason="requires python 3.5 or higher (non-comment type hints)")
147+
def test_type_hint_error2():
148+
""" Test for https://github.com/smarie/python-makefun/issues/32 """
149+
150+
from makefun.tests._test_py35 import make_ref_function2
151+
ref_f = make_ref_function2()
152+
153+
@wraps(ref_f)
154+
def foo(a):
155+
return a
156+
157+
assert foo(10) == 10

0 commit comments

Comments
 (0)