Skip to content

Commit

Permalink
Fixed NameError in case of unknown symbols in type hints. Fixes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain MARIE committed Apr 16, 2019
1 parent 5356f6e commit 4a069e5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions makefun/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ def _signature_symbol_needs_protection(symbol, evaldict):
try:
deflt = eval(repr(symbol), evaldict)
needs_protection = deflt != symbol
except NameError:
needs_protection = True
except SyntaxError:
needs_protection = True
else:
Expand Down
10 changes: 10 additions & 0 deletions makefun/tests/_test_py35.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ def ref(a: A) -> A:
pass

return ref


def make_ref_function2():
""" """
from typing import Any

def ref(a: Any):
pass

return ref
14 changes: 14 additions & 0 deletions makefun/tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,17 @@ def foo(a):
return a

assert foo(10) == 10


@pytest.mark.skipif(sys.version_info < (3, 5), reason="requires python 3.5 or higher (non-comment type hints)")
def test_type_hint_error2():
""" Test for https://github.com/smarie/python-makefun/issues/32 """

from makefun.tests._test_py35 import make_ref_function2
ref_f = make_ref_function2()

@wraps(ref_f)
def foo(a):
return a

assert foo(10) == 10

0 comments on commit 4a069e5

Please sign in to comment.