Skip to content

Commit 203d3a5

Browse files
author
Sylvain MARIE
committed
Fixed bug when the return type annotation of the function to create contains non-locally available type hints. Fixes #33
1 parent 0947148 commit 203d3a5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

makefun/main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,20 @@ def get_signature_string(func_name, func_signature, evaldict):
278278

279279
# if type hint can not be evaluated, protect it
280280
annotation_needs_protection = _signature_symbol_needs_protection(p.annotation, evaldict)
281-
new_annotation = _protect_signature_symbol(p.annotation, annotation_needs_protection, "HINT_%s" % p_name, evaldict)
281+
new_annotation = _protect_signature_symbol(p.annotation, annotation_needs_protection, "HINT_%s" % p_name,
282+
evaldict)
282283

283284
# replace the parameter with the possibly new default and hint
284285
p = Parameter(p.name, kind=p.kind, default=new_default, annotation=new_annotation)
285286
new_params.append(p)
286287

288+
# if return type hint can not be evaluated, protect it
289+
return_needs_protection = _signature_symbol_needs_protection(func_signature.return_annotation, evaldict)
290+
new_return_annotation = _protect_signature_symbol(func_signature.return_annotation, return_needs_protection,
291+
"RETURNHINT", evaldict)
292+
287293
# copy signature object
288-
s = Signature(parameters=new_params, return_annotation=func_signature.return_annotation)
294+
s = Signature(parameters=new_params, return_annotation=new_return_annotation)
289295

290296
# return the final string representation
291297
return "%s%s:" % (func_name, s)

makefun/tests/_test_py35.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def make_ref_function():
1818
class A:
1919
pass
2020

21-
def ref(a: A):
21+
def ref(a: A) -> A:
2222
pass
2323

2424
return ref

0 commit comments

Comments
 (0)