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

bpo-35224: Add support for NamedExpr to unparse.py #11670

Merged
merged 1 commit into from
Jan 25, 2019
Merged

bpo-35224: Add support for NamedExpr to unparse.py #11670

merged 1 commit into from
Jan 25, 2019

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jan 25, 2019

@vstinner
Copy link
Member Author

Oh, my first attempt without parenthesis failed: "(x := 1)" became "x := 1" which raises a SyntaxError. I modified my PR to always add parenthesis.

I will push this change to repair buildbots. If someone finds a smarter solution to omit parenthesis in some cases, please go ahead. I never used unparse.py. I don't think that it should nor that it can produce exactly the same input file, since Python looses many formatting information with code is compiled to bytecode (or even just when compiled to AST).

@vstinner
Copy link
Member Author

I tested manually on Linux: " ./python -m test test_tools -u all -v" pass with success.

@tirkarthi
Copy link
Member

cc @emilyemorehouse

@vstinner
Copy link
Member Author

Example:

vstinner@apu$ cat x.py 
str(x := 1)
str(y:=2)
(z:=3)

vstinner@apu$ ./python Tools/parser/unparse.py x.py 

str((x := 1))
str((y := 2))
(z := 3)

There are useless parentheses, but as I wrote, it's hard to emit the perfect code only from AST. And I wrote a quick fix to repair the CI ;-)

@vstinner vstinner merged commit 1396d8f into python:master Jan 25, 2019
@vstinner vstinner deleted the unparse_named_expr branch January 25, 2019 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants