Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.9, 3.14]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
Expand Down
16 changes: 13 additions & 3 deletions hyperpyyaml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import re
import ast
import sys
import yaml
import copy
import pydoc
Expand Down Expand Up @@ -715,9 +716,18 @@ def _ast_eval(node):
ast.Pow: op.pow,
ast.Mod: op.mod,
}
if isinstance(node, ast.Num): # <number>
return node.n
elif isinstance(node, ast.BinOp): # <left> <operator> <right>

# Compatibility check for Python versions
# In Python 3.8, ast.Num was deprecated and replaced by ast.Constant.
if sys.version_info >= (3, 8):
if isinstance(node, ast.Constant): # <number>, <string>, <bool>, <None>
return node.value
else:
# For Python versions older than 3.8
if isinstance(node, ast.Num): # <number>
return node.n

if isinstance(node, ast.BinOp): # <left> <operator> <right>
return ops[type(node.op)](_ast_eval(node.left), _ast_eval(node.right))
elif isinstance(node, ast.UnaryOp): # <operator> <operand> e.g., -1
return ops[type(node.op)](_ast_eval(node.operand))
Expand Down