Skip to content

Conversation

@Foxerine
Copy link

Summary

When using this library on Python 3.14, I encountered this error:

  File "C:\...\.venv314\Lib\site-packages\hyperpyyaml\core.py", line 718, in _ast_eval
    if isinstance(node, ast.Num):  # <number>
                        ^^^^^^^
AttributeError: module 'ast' has no attribute 'Num'

This PR fixes this error on Python 3.14+ and enhances the CI to ensure multi-version compatibility, including for Python 3.14. The changes should make the library more robust and future-proof.

Problem

The _ast_eval function uses ast.Num to evaluate numeric nodes, which is incompatible with modern Python versions.

According to the official documentation, the ast.Num class (along with ast.Str, ast.Bytes, etc.) was deprecated in Python 3.8 and scheduled for future removal. Starting in Python 3.8, ast.Constant became the unified node for all constants.

The original AttributeError on newer Python versions is a direct consequence of this deprecation and subsequent removal, causing hyperpyyaml to fail when parsing arithmetic references.

Solution

This patch resolves the issue by implementing a version-aware check within the _ast_eval function in hyperpyyaml/core.py:

  1. For Python versions 3.8 and newer, the code now correctly checks for ast.Constant and accesses its value via the .value attribute.
  2. For older Python versions (< 3.8), it preserves the original behavior by checking for ast.Num and using the .n attribute.

This approach ensures the library remains fully backward-compatible while supporting all modern Python interpreters.

Additional Improvements

  • CI Enhancement: The GitHub Actions workflow has been updated to run tests against both Python 3.9 and 3.14, validating the fix and preventing future regressions.

Updated the _ast_eval function to handle ast.Constant nodes for compatibility with Python 3.8 and newer, where ast.Num is deprecated. This ensures correct evaluation of constants across Python versions.
Adds Python 3.13 to the test matrix and updates actions/checkout and actions/setup-python to their latest major versions for improved compatibility and security.
Replaces Python 3.13 with 3.14 in the GitHub Actions matrix to ensure compatibility and testing with the latest Python release.
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.

1 participant