classification
Title: compile() error on AST object with assignment expression
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: emilyemorehouse, gvanrossum, pablogsal, serhiy.storchaka, tomyun
Priority: normal Keywords: patch

Created on 2019-03-17 22:10 by tomyun, last changed 2019-03-18 13:52 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12398 merged pablogsal, 2019-03-18 09:29
Messages (4)
msg338143 - (view) Author: Kyungdahm Yun (tomyun) Date: 2019-03-17 22:10
Seems like compile() can't properly handle assignment expressions parsed in AST object.

Python 3.8.0a2+ (heads/master:06e1e68, Mar 17 2019, 14:27:19)
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> compile("if a == 1:\n  True", '<string>', 'exec')
<code object <module> at 0x10a59ef60, file "<string>", line 1>
>>> compile(ast.parse("if a == 1:\n  True"), '<string>', 'exec')
<code object <module> at 0x10a5f6780, file "<string>", line 1>
>>> compile("if a := 1:\n  True", '<string>', 'exec')
<code object <module> at 0x10a59ef60, file "<string>", line 1>
>>> compile(ast.parse("if a := 1:\n  True"), '<string>', 'exec')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: unexpected expression
>>>

This issue seems to break IPython when trying to use any assignment expressions.
https://github.com/ipython/ipython/issues/11618
msg338161 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2019-03-18 04:14
Confirmed. Emily, do you need help tracking this down?
msg338163 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-03-18 06:25
validate_expr() needs a case for NamedExpr_kind.

I think also that it is better to remove the "default" clause (and move its code after the switch statement) and allow the compiler to warn about missed cases.
msg338223 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-03-18 13:51
New changeset 0c9258a6d299e0484538ef8d4b23f30515283db2 by Pablo Galindo in branch 'master':
bpo-36332: Allow compile() to handle AST objects with assignment expressions (GH-12398)
https://github.com/python/cpython/commit/0c9258a6d299e0484538ef8d4b23f30515283db2
History
Date User Action Args
2019-03-18 13:52:11pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-03-18 13:51:58pablogsalsetmessages: + msg338223
2019-03-18 09:31:18pablogsalsetnosy: + pablogsal
2019-03-18 09:29:01pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request12353
2019-03-18 06:25:16serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg338163
2019-03-18 04:14:43gvanrossumsetmessages: + msg338161
2019-03-18 01:19:23xtreaksetnosy: + gvanrossum, emilyemorehouse
2019-03-17 22:10:50tomyuncreate