Skip to content

Commit

Permalink
math_evaluator: Add Python 3.14 support
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Oct 18, 2024
1 parent a40d45c commit 2e4a733
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils/math_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ def visit_Expression(self, node):
return self.visit(node.body)

def visit_Num(self, node):
"""Python < 3.14 only"""
return self._convert_num(node.n)

def visit_Constant(self, node):
"""Python >= 3.14 only"""
if type(node.value) in (float, complex, int):
return self._convert_num(node.value)
else:
raise InvalidNode('illegal constant %s' % node.value)

def visit_Name(self, node):
id_ = node.id.lower()
if id_ in self._env:
Expand Down

0 comments on commit 2e4a733

Please sign in to comment.