Skip to content

Implement Py38 named expression (PEP 572) #1934

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

Merged
merged 26 commits into from
Jun 1, 2020

Conversation

TheAnyKey
Copy link
Contributor

@TheAnyKey TheAnyKey commented May 17, 2020

Python 3.8 instroduced named expressions or assignment expressions with PEP 572. Now it is possible

if f:=3>5: pass
or
foo(e:=42)

Most of the CPython tests are already passing. There are some scoping issues with mutli level (e.g., when a comprehension is inside of a comprehension, the asignments from the inner one are not leaked to the scope outside of the outer comrpehension). Further, there are no error messages when (ab)using iterator variables in named expressions. Both are generic topicsin RustPython and require a bit of rework in the symboltable and some other parts. As the functionality is complete besides of the scope limitation I propose to accept this PR.

@TheAnyKey
Copy link
Contributor Author

Be carefull, when testing it in an existing workspace as the bytecode changed. Although, I set the new instruction to the end, such that it should have no interference with already compiled bytecode files, I cannot ensure it.

@auvipy
Copy link

auvipy commented May 17, 2020

thanks for tackling this. codes look quite good

@TheAnyKey TheAnyKey force-pushed the TheAnyKey/p38_named_expr branch from 3ca1fba to 8bdd69c Compare May 23, 2020 22:27
@TheAnyKey TheAnyKey force-pushed the TheAnyKey/p38_named_expr branch from 8bdd69c to 3ca1fba Compare May 24, 2020 17:22
@TheAnyKey TheAnyKey force-pushed the TheAnyKey/p38_named_expr branch from 3ca1fba to 17008ef Compare May 24, 2020 20:36
@TheAnyKey TheAnyKey force-pushed the TheAnyKey/p38_named_expr branch from b4cc2d7 to 1968c5d Compare May 27, 2020 20:36
@TheAnyKey
Copy link
Contributor Author

Mostly done. Just need to add a few more checks, cleanup and merge. Some scoping issues will remain as they are an already existing RustPython problem. So we can fix that with a separate PR.

@TheAnyKey TheAnyKey marked this pull request as ready for review May 28, 2020 20:38
Copy link
Member

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for working on this!

@coolreader18
Copy link
Member

@windelbouwman could you take a look at the symbol table changes?

@windelbouwman
Copy link
Contributor

Ahh, nice, the infamous walrus operator! :=

@windelbouwman windelbouwman merged commit fd2e0aa into RustPython:master Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants