-
Notifications
You must be signed in to change notification settings - Fork 53
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
Unknown name "kind" on Constant for Python 3.7 #60
Comments
I am not a contributor, but I believe |
What do you suggest as an alternative for representing literal values, @pastelmind? After 3.8, This seems fixable directly in astunparse instead - I'll draft a patch. |
I did a How are you generating AST trees from code? If your code runs in Python < 3.8, it shouldn't see |
I am generating ASTs directly, not sourced from code, for example here: https://github.com/spenczar/avroc/blob/main/avroc/codegen/write.py#L289 I am compiling Avro data schema definitions into code objects. I use astunparse to populate the Python interpreter’s linecache so that stack traces work correctly (https://github.com/spenczar/avroc/blob/main/avroc/codegen/compiler.py#L86). I guess I could have switches in the code generator based on the Python version, but that seems pretty annoying to keep up with. astunparse could check if the kind attribute exists on the Constant object before using it. |
The
kind
attribute was added to the Constant expression in AST in Python 3.8. See https://bugs.python.org/issue36280.That means that in Python 3.7's
ast
module,Constants
never have a kind, so this line always errors.While
unparse
has made it in to Python 3.9'sast
module, I'd really like to useastunparse
as a sort of backport. It's still useful while Python 3.7 and 3.8 are in heavy use!The text was updated successfully, but these errors were encountered: