Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await inside f-string #2877

Open
fduxiao opened this Issue Mar 2, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@fduxiao
Copy link

fduxiao commented Mar 2, 2019

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.

@scoder

This comment has been minimized.

Copy link
Contributor

scoder commented Mar 3, 2019

Looks like a pure parser issue. Should be easy to fix by adding a test and making the parser use the right type of expression to parse inside of f-strings.
Note that the test should be in a .py file and use the pure3.6 tag to make sure Python only tests it in Py3.6+.

@HSR05

This comment has been minimized.

Copy link

HSR05 commented Mar 12, 2019

I would like to take this up. Can you guide me a little @scoder ? Thankyou 👍

@scoder

This comment has been minimized.

Copy link
Contributor

scoder commented 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.

@HSR05

This comment has been minimized.

Copy link

HSR05 commented Mar 13, 2019

@scoder thanks. I'll start working on it. 👍

@HSR05

This comment has been minimized.

Copy link

HSR05 commented Mar 19, 2019

@scoder i looked at p_f_string_expr() in Parsing.py. The parser does not parse await inside the f string. Can you guide me for writing the tests and also should i add parse function that parses await inside the p_f_string_expr(). This is my first issue in cython. I would be really thankful if you can guide me through it, so that i can improve in future. Thankyou. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.