dropbox / pyannotate

Auto-generate PEP-484 annotations
Apache License 2.0
1.43k stars 59 forks source link

Detect yield and return opcodes #56

Closed gvanrossum closed 6 years ago

gvanrossum commented 6 years ago

There are some hacks in MonkeyType that detect yield and return opcodes -- the former to generate Generator/Iterator return annotations, the latter to distinguish between return and exceptions.

gvanrossum commented 6 years ago

While #63 takes care of RETURN, I need to think more about how to do YIELD. Recognizing the opcode is simple enough, but the data structures in collect_types.py aren't really suitable to keep track of generators. Maybe the right thing is to check for the generator flag, treat YIELD as RETURN, and when we see the final RETURN, ignore its type? That would be sufficient for Python 2; yield from and async def/await are a different story again.

[UPDATE: For generators, additional problems are (1) how to get the args to the original generator, (2) how to get the value sent into the generator, if any.]