]> granicus.if.org Git - python/commit
Add ast.Constant
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 25 Jan 2016 23:40:57 +0000 (00:40 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 25 Jan 2016 23:40:57 +0000 (00:40 +0100)
commitf2c1aa1661edb3e14ff8b7b9995f93e303c8acbb
tree2b05f347dd55b86059d70197ce3d21210a668f91
parent0dceb918668399bdcbe27d1c59d01c4c9228c1a6
Add ast.Constant

Issue #26146: Add a new kind of AST node: ast.Constant. It can be used by
external AST optimizers, but the compiler does not emit directly such node.

An optimizer can replace the following AST nodes with ast.Constant:

* ast.NameConstant: None, False, True
* ast.Num: int, float, complex
* ast.Str: str
* ast.Bytes: bytes
* ast.Tuple if items are constants too: tuple
* frozenset

Update code to accept ast.Constant instead of ast.Num and/or ast.Str:

* compiler
* docstrings
* ast.literal_eval()
* Tools/parser/unparse.py
14 files changed:
Include/Python-ast.h
Include/asdl.h
Lib/ast.py
Lib/test/test_ast.py
Misc/NEWS
Parser/Python.asdl
Parser/asdl.py
Parser/asdl_c.py
Python/Python-ast.c
Python/ast.c
Python/compile.c
Python/future.c
Python/symtable.c
Tools/parser/unparse.py