For what it's worth, Larry's PEP 649 branch currently prohibits yield, yield from, await, and the walrus operator in annotations. That seems like the right choice unless there's some realistic use case for any of these.

El vie, 23 abr 2021 a las 11:27, Batuhan Taskaya (<>) escribió:
About 4 months ago, I've created bpo-42725 in order to
resolve some of the points below though I decided to
postpone it for various reasons that blocked it completely
until the point of where we have a beta cut in a week or
so. So I'm asking for comments regarding how should we resolve
this behavior.

Even though PEP 563 blocks having all compiler-related activities
for annotations by behaving them strings, this doesn't happen until
the symbol is constructed which results with different problems. For
example you can use yield in annotation, and since PEP 563 will stringify
it you'd expect your function to act accordingly but it currently doesn't.
Also references to the upper scope variables will still be contained as closures
of the current function, and some other oddities that I've found regarding misc
stuff (usage of super() etc).

Here is a quick demo:

def foo():
    for number in range(5):
        foo: (yield number)
    return number

foo() # ======> this will be a generator

We could go with acting these as strings and letting them stay as annotations
but making them no-op on the symbol table (which is the straight forward choice)
or we could restrict usage of those inside of annotations and raise
SyntaxErrors. I've
drafted patches for both of those ideas, though it definitely needs
more work and
there is not much time left so any comments would be appreciated.

P.S: I intend to submit a PR with the most likely option by, at latest, end of
saturday so that we can give reviewers enough time and also catch the
beta freeze
considering this is a clear behavioral change.
Python-Dev mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: