question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

await inside f-string

See original GitHub issue

When I tried cythonizing

async def abc():
    return "abc"


async def main():
    print(f"{await abc()}")

I got

Error compiling Cython file:
------------------------------------------------------------
...
async def abc():
    return "abc"


async def main():
    print(f"{await abc()}")
                   ^
------------------------------------------------------------

test.pyx:6:20: Expected ')', found 'abc'

I’m sure python can run it directly. It seems that cython won’t parse await inside f-string, and I have to split it into two lines now.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
scodercommented, Mar 13, 2019

Sure. The parser is in Parsing.py, look for p_f_string_expr(), which parses the expressions. Check CPython’s Grammar file to see what kind of expression is allowed there, and compare it to what Cython’s parser expects. Make sure Cython’s parser uses a parse function that accepts await. For tests, I think we should finally have a separate Cython specific test for async-await, in addition to CPython’s own tests that we run. Create a new test file tests/run/async_await.pyx, implement a test coroutine function in there and give it a doctest that asserts the necessary behaviour. See https://github.com/cython/cython/wiki/HackerGuide#tests on how to run that test.

0reactions
scodercommented, Aug 21, 2019

Implemented in #3070.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why isn't it possible to use "await" in f-strings? - Stack Overflow
Show activity on this post. As of Python 3.6 , this is not possible. It will be possible in 3.7 according to the...
Read more >
Issue 28942: await expressions in f-strings - Python tracker
> I was going to say "no", but given that "yield" works, I think it is reasonable to allow "await" as well. (And...
Read more >
Await inside JavaScript template strings - DEV Community ‍ ‍
Did you know it is possible to use await inside interpolated JavaScript template strings (aka template literals)? I personally did not, ...
Read more >
consider-using-f-string / C0209 - Pylint
Formatted string literals (f-strings) give a concise, consistent syntax that can replace most use cases for the % formatting operator, str.format() and string....
Read more >
Template literals (Template strings) - JavaScript | MDN
However, a tagged template literal may not result in a string; it can be used with a custom tag function to perform whatever...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found