Skip to content

Commit

Permalink
Fix deprecation warnings
Browse files Browse the repository at this point in the history
Co-authored-by: Edgar Ramírez Mondragón <[email protected]>
  • Loading branch information
danthedeckie and edgarrmondragon committed Oct 4, 2024
1 parent 866004e commit d23ad09
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions simpleeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
- smurfix (Matthias Urlichs) Allow clearing functions / operators / etc completely
- koenigsley (Mikhail Yeremeyev) documentation typos correction.
- kurtmckee (Kurt McKee) Infrastructure updates
- edgarrmondragon (Edgar Ramírez-Mondragón) Address Python 3.12+ deprecation warnings
-------------------------------------
Basic Usage:
Expand Down Expand Up @@ -352,8 +353,6 @@ def __init__(self, operators=None, functions=None, names=None):
ast.Assign: self._eval_assign,
ast.AugAssign: self._eval_aug_assign,
ast.Import: self._eval_import,
ast.Num: self._eval_num,
ast.Str: self._eval_str,
ast.Name: self._eval_name,
ast.UnaryOp: self._eval_unaryop,
ast.BinOp: self._eval_binop,
Expand All @@ -366,12 +365,22 @@ def __init__(self, operators=None, functions=None, names=None):
ast.Attribute: self._eval_attribute,
ast.Index: self._eval_index,
ast.Slice: self._eval_slice,
ast.NameConstant: self._eval_constant,
ast.JoinedStr: self._eval_joinedstr,
ast.FormattedValue: self._eval_formattedvalue,
ast.Constant: self._eval_constant,
}

# py3.12 deprecated ast.Num, ast.Str, ast.NameConstant
# https://docs.python.org/3.12/whatsnew/3.12.html#deprecated
if Num := getattr(ast, "Num"):
self.nodes[Num] = self._eval_num

if Str := getattr(ast, "Str"):
self.nodes[Str] = self._eval_str

if NameConstant := getattr(ast, "NameConstant"):
self.nodes[NameConstant] = self._eval_constant

# Defaults:

self.ATTR_INDEX_FALLBACK = ATTR_INDEX_FALLBACK
Expand Down

0 comments on commit d23ad09

Please sign in to comment.