Skip to content

Commit 064ae93

Browse files
committed
Align simple_eval with Python 3.10+ (fixes #1035)
1 parent b5f428c commit 064ae93

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

bpython/simpleeval.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@
2626
"""
2727

2828
import ast
29-
import sys
3029
import builtins
31-
from typing import Dict, Any, Optional
30+
from typing import Any
3231

3332
from . import line as line_properties
3433
from .inspection import getattr_safe
3534

36-
_string_type_nodes = (ast.Str, ast.Bytes)
3735
_numeric_types = (int, float, complex)
38-
_name_type_nodes = (ast.Name,)
3936

4037

4138
class EvaluationError(Exception):
@@ -123,7 +120,7 @@ def _convert(node):
123120
return list()
124121

125122
# this is a deviation from literal_eval: we allow non-literals
126-
elif isinstance(node, _name_type_nodes):
123+
elif isinstance(node, ast.Name):
127124
try:
128125
return namespace[node.id]
129126
except KeyError:
@@ -147,7 +144,9 @@ def _convert(node):
147144
elif isinstance(node, ast.BinOp) and isinstance(
148145
node.op, (ast.Add, ast.Sub)
149146
):
150-
# ast.literal_eval does ast typechecks here, we use type checks
147+
# this is a deviation from literal_eval: ast.literal_eval accepts
148+
# (+/-) int, float and complex literals as left operand, and complex
149+
# as right operation, we evaluate as much as possible
151150
left = _convert(node.left)
152151
right = _convert(node.right)
153152
if not (

0 commit comments

Comments
 (0)