await inside f-string
See original GitHub issueWhen 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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure. The parser is in
Parsing.py
, look forp_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 acceptsawait
. 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 filetests/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.Implemented in #3070.