[Python-Dev] PEP 492 quibble and request (original) (raw)
Steven D'Aprano steve at pearwood.info
Fri May 1 13:54:48 CEST 2015
- Previous message (by thread): [Python-Dev] PEP 492 quibble and request
- Next message (by thread): [Python-Dev] PEP 492 quibble and request
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Apr 29, 2015 at 07:31:22PM -0700, Guido van Rossum wrote:
Ah, but here's the other clever bit: it's only interpreted this way inside a function declared with 'async def'. Outside such functions, 'await' is not a keyword, so that grammar rule doesn't trigger. (Kind of similar to the way that the printfunction future disables the keyword-ness of 'print', except here it's toggled on or off depending on whether the nearest surrounding scope is 'async def' or not. The PEP could probably be clearer about this; it's all hidden in the Transition Plan section.)
You mean we could write code like this?
def await(x): ...
if condition: async def spam(): await (eggs or cheese) else: def spam(): await(eggs or cheese)
I must admit that's kind of cool, but I'm sure I'd regret it.
-- Steve
- Previous message (by thread): [Python-Dev] PEP 492 quibble and request
- Next message (by thread): [Python-Dev] PEP 492 quibble and request
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]