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

parser fails to parse starred expression with language_level=3 #2939

Closed
jahodfra opened this issue Apr 30, 2019 · 4 comments
Closed

parser fails to parse starred expression with language_level=3 #2939

jahodfra opened this issue Apr 30, 2019 · 4 comments

Comments

@jahodfra
Copy link

(env) vagrant@h2o:~/h2oai$ cython -3 test.pyx 

Error compiling Cython file:
------------------------------------------------------------
...
def results_check(*args):
    "%s %s" % ('2', *args)
                   ^
------------------------------------------------------------

test.pyx:2:20: starred expression is not allowed here
(env) vagrant@h2o:~/h2oai$ python3 test.pyx 
(env) vagrant@h2o:~/h2oai$ cython -2 test.pyx 
(env) vagrant@h2o:~/h2oai$ python2 test.pyx 
  File "test.pyx", line 2
    "%s %s" % ('2', *args)
                    ^
SyntaxError: invalid syntax
@jahodfra
Copy link
Author

jahodfra commented Apr 30, 2019

"Cython version 0.28.3"

@scoder
Copy link
Contributor

scoder commented Apr 30, 2019

Interesting. I can confirm that it generates the correct code with language level 2, but fails with language level 3. My guess was that this is due to the string formatting optimisation into f-strings, which was added in 0.28 and only applies to unicode strings (not Py2 byte strings). The expression then becomes f"{'2'} {*args}", and that does not work. Looks like we have to explicitly exclude star-expressions.

@scoder scoder added this to the 0.29.8 milestone Apr 30, 2019
@scoder scoder closed this as completed in 09ca6da Apr 30, 2019
@scoder
Copy link
Contributor

scoder commented Apr 30, 2019

Thanks for the report and the short reproducer.

@jahodfra
Copy link
Author

Thank you for confirmation and fast response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants