Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-38870: Expose a function to unparse an ast object in the ast module#17302

Merged
pablogsal merged 15 commits into
python:masterpython/cpython:masterfrom
pablogsal:bpo-38870pablogsal/cpython:bpo-38870Copy head branch name to clipboard
Nov 24, 2019
Merged

bpo-38870: Expose a function to unparse an ast object in the ast module#17302
pablogsal merged 15 commits into
python:masterpython/cpython:masterfrom
pablogsal:bpo-38870pablogsal/cpython:bpo-38870Copy head branch name to clipboard

Conversation

@pablogsal

@pablogsal pablogsal commented Nov 20, 2019

Copy link
Copy Markdown
Member

https://bugs.python.org/issue38870

⚠️ Note that this PR only exposes the function in the ast module and does not improve on the base code to avoid creating a gigantic PR when fixing cosmetic changes and adding options. ⚠️

@pablogsal

Copy link
Copy Markdown
Member Author

CC: @isidentical

@pablogsal pablogsal self-assigned this Nov 20, 2019
Comment thread Lib/ast.py Outdated
Comment thread Lib/ast.py Outdated
@isidentical

Copy link
Copy Markdown
Member

I'm not sure if this is the right place to discuss API issues but if it isn't, I can submit a PR with these fixes to discuss.

Comment thread Doc/whatsnew/3.9.rst
Comment thread Lib/test/test_unparse.py Outdated
basepath = (pathlib.Path(__file__).parent / ".." / "..").resolve()
test_dir = os.path.join(basepath, d)
for n in os.listdir(test_dir):
for n in os.listdir(test_dir):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMHO using sole pathlib would be a good addition instead of mixing os.path and pathlib

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree, will change this soon

…e can give preceding information for traverse

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, looks good! IIUC the discussed improvements will be added in separate PRs.

Comment thread Lib/test/test_unparse.py Outdated
@isidentical

Copy link
Copy Markdown
Member

Thanks @ilevkivskyi for reviews

@pablogsal pablogsal merged commit 27fc3b6 into python:master Nov 24, 2019
@pablogsal pablogsal deleted the bpo-38870 branch November 24, 2019 23:02
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
…le (pythonGH-17302)

Add ast.unparse() as a function in the ast module that can be used to unparse an
ast.AST object and produce a string with code that would produce an equivalent ast.AST
object when parsed.
@Zac-HD

Zac-HD commented Dec 19, 2019

Copy link
Copy Markdown
Contributor

Running Zac-HD/hypothesmith@98d6a7c for a while doesn't find any cases where ast.parse / ast.unparse / ast.parse failed to round-trip 🎉

@pablogsal

Copy link
Copy Markdown
Member Author

Running Zac-HD/hypothesmith@98d6a7c for a while doesn't find any cases where ast.parse / ast.unparse / ast.parse failed to round-trip 🎉

Thanks for telling us, @Zac-HD :)

@Zac-HD

Zac-HD commented Dec 19, 2019

Copy link
Copy Markdown
Contributor

I mention it because lib2to3 and tokenize both fail to round-trip for certain weird edge cases!

shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
…le (pythonGH-17302)

Add ast.unparse() as a function in the ast module that can be used to unparse an
ast.AST object and produce a string with code that would produce an equivalent ast.AST
object when parsed.
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.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.