This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python 3.5 can't compile AST involving PEP 448 unpacking
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, brett.cannon, dabeaz, larry, ncoghlan, ned.deily, python-dev, serhiy.storchaka, terry.reedy, yselivanov
Priority: release blocker Keywords: patch

Created on 2015-09-01 01:13 by dabeaz, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue24975.patch yselivanov, 2015-09-01 03:04 review
Messages (11)
msg249442 - (view) Author: David Beazley (dabeaz) Date: 2015-09-01 01:13
The compile() function is not able to compile an AST created from code that uses some of the new unpacking generalizations in PEP 448.  Example:

code = '''                                                                     
a = { 'x':1, 'y':2 }
b = { **a, 'z': 3 }
'''

# Works
ccode = compile(code, '', 'exec')

# Crashes
import ast
tree = ast.parse(code)
ccode = compile(tree, '', 'exec')

# ----------------------------------

Error Traceback:

Traceback (most recent call last):
  File "bug.py", line 11, in <module>
    ccode = compile(tree, '', 'exec')
ValueError: None disallowed in expression list

Note:  This bug makes it impossible to try generalized unpacking examples interactively in IPython.
msg249448 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-09-01 03:04
Good find, David. Thanks!

Please review the attached patch.
msg249451 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-09-01 04:01
Good catch!  Please file a pull request via bitbucket.
msg249452 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-09-01 05:14
Patch looks good to me. I was initially going to query the changes to the break/continue AST tests, but then realised they were needed to avoid a compile error for break/continue outside a loop now that we ensure the resulting AST can be used to generate code.
msg249498 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-09-01 18:13
Do we not have a test that compiles the entire stdlib using the ast module? We used to have one for the old compiler package. If don't have such a test we should probably add it even if it requires a -u option.
msg249515 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-09-01 20:13
Larry,

I created a PR for you: https://bitbucket.org/larry/cpython350/pull-requests/10/issue-24975-fix-ast-compilation-for-pep/diff

Brett,

Should we do that in a separate issue targeting 3.6 only?
msg249517 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-09-01 20:49
Created issue #24981 to track the test case idea.
msg249563 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-09-02 19:37
Merged.  Please forward-merge to 3.5.1 and 3.6, thanks!
msg249564 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-02 19:50
New changeset e9df8543d7bc by Yury Selivanov in branch '3.5':
Issue #24975: Fix AST compilation for PEP 448 syntax.
https://hg.python.org/cpython/rev/e9df8543d7bc

New changeset ea79be5b201e by Yury Selivanov in branch '3.5':
Merge 3.5 heads (issue #24975)
https://hg.python.org/cpython/rev/ea79be5b201e

New changeset 1dcd7f257ed8 by Yury Selivanov in branch 'default':
Merge 3.5 (issue #24975)
https://hg.python.org/cpython/rev/1dcd7f257ed8
msg249565 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-09-02 19:51
Thanks Nick and Larry for code reviews and merge!
msg249838 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 21:46
Upon writing a proof-of-concept file for #24981, I discovered an stdlib file that gave the same error.

C:/programs/Python35/Lib\distutils/_msvccompiler.py
ValueError: None disallowed in expression list

I presume the applied fix will apply to this also.
History
Date User Action Args
2022-04-11 14:58:20adminsetnosy: + ned.deily
github: 69163
2015-09-04 21:46:54terry.reedysetnosy: + terry.reedy
messages: + msg249838
2015-09-02 19:51:32yselivanovsetstatus: open -> closed
resolution: fixed
messages: + msg249565

stage: patch review -> resolved
2015-09-02 19:50:36python-devsetnosy: + python-dev
messages: + msg249564
2015-09-02 19:37:53larrysetmessages: + msg249563
2015-09-01 20:49:43brett.cannonsetmessages: + msg249517
2015-09-01 20:13:17yselivanovsetmessages: + msg249515
2015-09-01 18:13:40brett.cannonsetnosy: + brett.cannon
messages: + msg249498
2015-09-01 05:14:28ncoghlansetmessages: + msg249452
2015-09-01 04:01:54larrysetmessages: + msg249451
2015-09-01 03:04:02yselivanovsetfiles: + issue24975.patch
priority: normal -> release blocker

versions: + Python 3.6
keywords: + patch
nosy: + ncoghlan, larry, benjamin.peterson, serhiy.storchaka, yselivanov

messages: + msg249448
stage: patch review
2015-09-01 01:13:16dabeazcreate