Commit 7941b93a authored by Stefan Behnel's avatar Stefan Behnel

Add missing return type annotation to generators and coroutines.

Closes GH-2884.
parent 61505ce4
...@@ -14,6 +14,9 @@ Bugs fixed ...@@ -14,6 +14,9 @@ Bugs fixed
* Casting a GIL-requiring function into a nogil function now issues a warning. * Casting a GIL-requiring function into a nogil function now issues a warning.
(Github issue #2879) (Github issue #2879)
* Generators and coroutines were missing their return type annotation.
(Github issue #2884)
0.29.6 (2019-02-27) 0.29.6 (2019-02-27)
=================== ===================
......
...@@ -2624,7 +2624,8 @@ class MarkClosureVisitor(CythonTransform): ...@@ -2624,7 +2624,8 @@ class MarkClosureVisitor(CythonTransform):
pos=node.pos, name=node.name, args=node.args, pos=node.pos, name=node.name, args=node.args,
star_arg=node.star_arg, starstar_arg=node.starstar_arg, star_arg=node.star_arg, starstar_arg=node.starstar_arg,
doc=node.doc, decorators=node.decorators, doc=node.doc, decorators=node.decorators,
gbody=gbody, lambda_name=node.lambda_name) gbody=gbody, lambda_name=node.lambda_name,
return_type_annotation=node.return_type_annotation)
return coroutine return coroutine
def visit_CFuncDefNode(self, node): def visit_CFuncDefNode(self, node):
......
...@@ -551,3 +551,11 @@ def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwar ...@@ -551,3 +551,11 @@ def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwar
result : int = a + b result : int = a + b
return result return result
async def async_def_annotations(x: 'int') -> 'float':
"""
>>> sorted(async_def_annotations.__annotations__.items())
[('return', 'float'), ('x', 'int')]
"""
return float(x)
...@@ -22,3 +22,14 @@ def with_outer_raising(*args): ...@@ -22,3 +22,14 @@ def with_outer_raising(*args):
yield i yield i
raise StopIteration raise StopIteration
return generator return generator
def anno_gen(x: 'int') -> 'float':
"""
>>> gen = anno_gen(2)
>>> next(gen)
2.0
>>> sorted(anno_gen.__annotations__.items())
[('return', 'float'), ('x', 'int')]
"""
yield float(x)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment