Skip to content

Implement Py38 named expression (PEP 572) - #1934

Merged
windelbouwman merged 26 commits into
RustPython:masterfrom
TheAnyKey:TheAnyKey/p38_named_expr
Jun 1, 2020
Merged

Implement Py38 named expression (PEP 572)#1934
windelbouwman merged 26 commits into
RustPython:masterfrom
TheAnyKey:TheAnyKey/p38_named_expr

Conversation

@TheAnyKey

@TheAnyKey TheAnyKey commented May 17, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

auvipy commented May 17, 2020

Copy link
Copy Markdown

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
Copy Markdown
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

@coolreader18 coolreader18 left a comment

Copy link
Copy Markdown
Member

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!

Comment thread compiler/src/symboltable.rs
@coolreader18

Copy link
Copy Markdown
Member

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

@windelbouwman

Copy link
Copy Markdown
Contributor

Ahh, nice, the infamous walrus operator! :=

Comment thread parser/src/python.lalrpop Outdated
Comment thread compiler/src/symboltable.rs
Comment thread compiler/src/symboltable.rs Outdated
Comment thread compiler/src/symboltable.rs
Comment thread compiler/src/symboltable.rs
@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