Skip to content

Remove the dependency on astor for Pythons ≥ 3.9 #1999

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 5 commits into from
Mar 17, 2021

Conversation

Kodiologist
Copy link
Member

@Kodiologist Kodiologist commented Mar 16, 2021

Python 3.9 added ast.unparse, which can do most of the work. It has some bugs that I fixed in astor, which I've worked around here, but I've submitted a patch to CPython to fix them for real (python/cpython#24897).

Copy link
Member

@scauligi scauligi left a comment

Choose a reason for hiding this comment

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

Aside from a few more small changes, lgtm

hy/_compat.py Outdated

if PY3_9:

import ast, math, cmath
Copy link
Member

Choose a reason for hiding this comment

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

The math and cmath imports appear irrelevant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, they're leftovers.


import ast, math, cmath
class Unparser(ast._Unparser):
# Work around some limitations of Python's `ast.unparse`.
Copy link
Member

Choose a reason for hiding this comment

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

Add a reference to python/cpython#24897. Since it's going to be backported to 3.9, we can eventually remove this workaround once it lands.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

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.

3 participants