Visitar URL original
bpo-36332: Allow compile() to handle AST objects with assignment expressions by pablogsal · Pull Request #12398 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260217231930/https://github.com/python/cpython/pull/12398
Skip to content
/ cpython Public

bpo-36332: Allow compile() to handle AST objects with assignment expressions#12398

Merged
pablogsal merged 2 commits intopython:masterfrom
pablogsal:bpo36332
Mar 18, 2019
Merged

bpo-36332: Allow compile() to handle AST objects with assignment expressions#12398
pablogsal merged 2 commits intopython:masterfrom
pablogsal:bpo36332

Conversation

@pablogsal
Copy link
Member

@pablogsal pablogsal commented Mar 18, 2019 •

@pablogsal
Copy link
Member Author

As @serhiy-storchaka suggested, I have moved the default cause of the switch outside so the compiler now emits warnings if there are missing cases. For example:

Python/ast.c: In function ‘validate_expr’:
Python/ast.c:226:5: warning: enumeration value ‘NamedExpr_kind’ not handled in switch [-Wswitch]
     switch (exp->kind) {
     ^~~~~~

Python/ast.c Outdated
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: I prefer the current "default:" case coding style :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

The advantage of having it outside the switch is that the compiler complains about missing cases. Check my previous comment and Serhiy's suggestion in the bpo

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, I see. It makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

Why not add it to exec_tests or single_tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was afraid that the diff will be very difficult to read because the regenerated exec_results, but it turned out to be very simple. I have added the test to exec_results instead of creating a new extra_validation_snippets.

@pablogsal pablogsal force-pushed the bpo36332 branch 3 times, most recently from 3fd32ec to b71484a Compare March 18, 2019 11:09
# Decorator with generator argument
"@deco(a for a in b)\ndef f(): pass",
# Simple assignment expression
"if a:=1:\n True"
Copy link
Member

Choose a reason for hiding this comment

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

Minimal example: "(a := 1)".

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

@pablogsal pablogsal merged commit 0c9258a into python:master Mar 18, 2019
@pablogsal pablogsal deleted the bpo36332 branch March 18, 2019 13:52
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