Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 24, 2019

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Nov 20, 2019

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
Member Author

CC: @isidentical

Verified

This commit was signed with the committer’s verified signature.
pablogsal Pablo Galindo Salgado

Verified

This commit was signed with the committer’s verified signature.
pablogsal Pablo Galindo Salgado

Verified

This commit was signed with the committer’s verified signature.
pablogsal Pablo Galindo Salgado
@pablogsal pablogsal self-assigned this Nov 20, 2019
@isidentical
Copy link
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.

test_dir = os.path.join(basepath, d)
for n in os.listdir(test_dir):
for n in os.listdir(test_dir):
Copy link
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
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
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

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.

@isidentical
Copy link
Member

Thanks @ilevkivskyi for reviews

Verified

This commit was signed with the committer’s verified signature.
pablogsal Pablo Galindo Salgado

Verified

This commit was signed with the committer’s verified signature.
pablogsal Pablo Galindo Salgado
@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
Copy link
Contributor

Zac-HD commented Dec 19, 2019

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
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
Copy link
Contributor

Zac-HD commented Dec 19, 2019

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.

None yet

6 participants