2626"""
2727
2828import ast
29- import sys
3029import builtins
31- from typing import Dict , Any , Optional
30+ from typing import Any
3231
3332from . import line as line_properties
3433from .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
4138class 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