Repository navigation
Closed
Labels
3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/pablogsal'
closed_at = <Date 2020-10-23.18:24:39.319>
created_at = <Date 2019-11-20.22:34:29.558>
labels = ['type-feature', 'library', '3.9']
title = 'Expose ast.unparse in the ast module'
updated_at = <Date 2020-10-23.18:24:39.319>
user = 'https://github.com/pablogsal'bugs.python.org fields:
activity = <Date 2020-10-23.18:24:39.319>
actor = 'BTaskaya'
assignee = 'pablogsal'
closed = True
closed_date = <Date 2020-10-23.18:24:39.319>
closer = 'BTaskaya'
components = ['Library (Lib)']
creation = <Date 2019-11-20.22:34:29.558>
creator = 'pablogsal'
dependencies = []
files = []
hgrepos = []
issue_num = 38870
keywords = ['patch']
message_count = 33.0
messages = ['357107', '357111', '357138', '357176', '357258', '357417', '357438', '358478', '358504', '358824', '358826', '359001', '359207', '359500', '359502', '359508', '363087', '363196', '363768', '364257', '367985', '369069', '369070', '369076', '369078', '369088', '369286', '369289', '369398', '369402', '372488', '372490', '379462']
nosy_count = 7.0
nosy_names = ['levkivskyi', 'pablogsal', 'miss-islington', 'brandtbucher', 'BTaskaya', 'Batuhan Taskaya', '1v3m']
pr_nums = ['17302', '17376', '17377', '17612', '17613', '17687', '17738', '17739', '17760', '17797', '17798', '17892', '18768', '19016', '19636', '20133', '20134', '20141', '20152', '20166', '20240', '20244', '21053', '21191']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue38870'
versions = ['Python 3.9']Metadata
Metadata
Assignees
Labels
3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Activity
pablogsal commentedon Nov 20, 2019
As discussed in https://mail.python.org/archives/list/python-dev@python.org/thread/JAQDBMC23HW2PQ27HQNJ7G244T423IDD/ I propose to expose the unparse.py tool as part of the standard library in the ast module.
The exposed function will have the interface:
and will return a string with the unparsed version of ast_obj.
The unparse tool will need some cosmetic improvements that will be tracked separately in this issue.
pablogsal commentedon Nov 20, 2019
After PR17302 is merged we need to fix the following cosmetic issues indicated by Victor:
(*) unparse adds many useless parentheses. The algorithm seems naive.
For example, it adds "()" to "class _AddedDllDirectory():". It also
adds parenthesis around yield, like "(yield (top, dirs, nondirs))",
whereas the AST node was at "top level": it isn't a sub-expression.
Maybe this algortihm should be made smarter.
(*) newlines in docstring are rendered as two characters: "\" + "n"
(escaped newline: \n), rather than a newline character. I would expect
a newline, it's more common that \n... But it may "break" inline
doctests rendering... Maybe it should be an option (render newlines as
newline character or escape them?), or maybe even let the user choose
how to render them using a callback (that's related to the "pluggable
formatter" question).
(*) Indentation is hardcoded to 4 spaces. What if I want 2 spaces or
something different? Should it become an option?
(*) Float infinity is replaces with 1e309. Again, maybe someone wants
to render this differently? It sounds like an arbitrary choice (which
"works" as expected).
BatuhanTaskaya commentedon Nov 21, 2019
After PR 17302 is accepted, I'll work on refactorings including a precedence algorithm to find when to parentheses.
isidentical commentedon Nov 21, 2019
@gvanrossum are you OK with adding type comments support? Current version loses type comment information so if typed_ast parses this, they wont be the same in AST representation.
gvanrossum commentedon Nov 22, 2019
Good catch, definitely do that!
pablogsal commentedon Nov 24, 2019
New changeset 27fc3b6 by Pablo Galindo in branch 'master':
bpo-38870: Expose a function to unparse an ast object in the ast module (GH-17302)
27fc3b6
miss-islington commentedon Nov 25, 2019
New changeset ded8888 by Miss Islington (bot) (Pablo Galindo) in branch 'master':
bpo-38870: Remove dependency on contextlib to avoid performance regression on import (GH-17376)
ded8888
pablogsal commentedon Dec 16, 2019
New changeset a322f50 by Pablo Galindo (Batuhan Taşkaya) in branch 'master':
bpo-38870: Remove dead code related with argument unparsing (GH-17613)
a322f50
vstinner commentedon Dec 16, 2019
I created bpo-39069: "Move ast.unparse() function to a different module".
pablogsal commentedon Dec 23, 2019
New changeset 4b3b122 by Pablo Galindo (Batuhan Taşkaya) in branch 'master':
bpo-38870: Refactor delimiting with context managers in ast.unparse (GH-17612)
4b3b122
pablogsal commentedon Dec 23, 2019
New changeset d69cbeb by Pablo Galindo in branch 'master':
Revert "bpo-38870: Remove dependency on contextlib to avoid performance regression on import (GH-17376)" (GH-17687)
d69cbeb
9 remaining items
pablogsal commentedon May 3, 2020
New changeset 493bf1c by Batuhan Taskaya in branch 'master':
bpo-38870: Don't start generated output with newlines in ast.unparse (GH-19636)
493bf1c
pablogsal commentedon May 16, 2020
New changeset ce4a753 by Batuhan Taskaya in branch 'master':
bpo-38870: Do not separate factor prefixes in ast.unparse (GH-20133)
ce4a753
pablogsal commentedon May 16, 2020
New changeset 25160cd by Batuhan Taskaya in branch 'master':
bpo-38870: Don't put unnecessary parentheses on class declarations in ast.parse (GH-20134)
25160cd
pablogsal commentedon May 16, 2020
New changeset e966af7 by Batuhan Taskaya in branch 'master':
bpo-38870: Correctly handle empty docstrings in ast.unparse (GH-18768)
e966af7
pablogsal commentedon May 16, 2020
New changeset dff92bb by Batuhan Taskaya in branch 'master':
bpo-38870: Implement round tripping support for typed AST in ast.unparse (GH-17797)
dff92bb
pablogsal commentedon May 17, 2020
New changeset 6341fc7 by Pablo Galindo in branch 'master':
bpo-38870: Use subTest in test_unparse for better error reporting (GH-20141)
6341fc7
pablogsal commentedon May 18, 2020
New changeset d71a649 by CyberSaxosTiGER in branch 'master':
bpo-38870: correctly escape unprintable characters on ast.unparse (GH-20166)
d71a649
pablogsal commentedon May 18, 2020
New changeset c102a14 by Batuhan Taskaya in branch 'master':
bpo-38870: Don't omit parenthesis when unparsing a slice in ast.unparse
c102a14
miss-islington commentedon May 19, 2020
New changeset dd74b6f by Batuhan Taskaya in branch 'master':
bpo-38870: invalid escape sequence (GH-20240)
dd74b6f
miss-islington commentedon May 19, 2020
New changeset 059279d by Miss Islington (bot) in branch '3.9':
bpo-38870: invalid escape sequence (GH-20240)
059279d
pablogsal commentedon Jun 28, 2020
New changeset 8df1016 by Batuhan Taskaya in branch 'master':
bpo-38870: Extend subject of ast.unparse warnings (GH-21053)
8df1016
pablogsal commentedon Jun 28, 2020
New changeset 6e39999 by Pablo Galindo in branch '3.9':
[3.9] bpo-38870: Extend subject of ast.unparse warnings (GH-21053) (GH-21191)
6e39999
isidentical commentedon Oct 23, 2020
Well, I'm happy to say that 3.9.0 is finally released with the ast.unparse interface. After tens of PRs, I think it is time for us to move on. For all future bugs, please create a new issue and nosy me. Thanks everyone who has participated this journey!