mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
The evaluator recursion limitations are now reset in static analysis for each node, otherwise it's incredibly unprecise.
This commit is contained in:
@@ -571,6 +571,7 @@ class Script(object):
|
|||||||
unpack_tuple_to_dict(self._evaluator, types, testlist)
|
unpack_tuple_to_dict(self._evaluator, types, testlist)
|
||||||
else:
|
else:
|
||||||
try_iter_content(self._evaluator.goto_definition(node))
|
try_iter_content(self._evaluator.goto_definition(node))
|
||||||
|
self._evaluator.reset_recursion_limitations()
|
||||||
|
|
||||||
ana = [a for a in self._evaluator.analysis if self.path == a.path]
|
ana = [a for a in self._evaluator.analysis if self.path == a.path]
|
||||||
return sorted(set(ana), key=lambda x: x.line)
|
return sorted(set(ana), key=lambda x: x.line)
|
||||||
|
|||||||
@@ -86,8 +86,6 @@ class Evaluator(object):
|
|||||||
# To memorize modules -> equals `sys.modules`.
|
# To memorize modules -> equals `sys.modules`.
|
||||||
self.modules = {} # like `sys.modules`.
|
self.modules = {} # like `sys.modules`.
|
||||||
self.compiled_cache = {} # see `compiled.create()`
|
self.compiled_cache = {} # see `compiled.create()`
|
||||||
self.recursion_detector = recursion.RecursionDetector(self)
|
|
||||||
self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self)
|
|
||||||
self.analysis = []
|
self.analysis = []
|
||||||
self.predefined_if_name_dict_dict = {}
|
self.predefined_if_name_dict_dict = {}
|
||||||
self.is_analysis = False
|
self.is_analysis = False
|
||||||
@@ -100,9 +98,15 @@ class Evaluator(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
self.reset_recursion_limitations()
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
self.BUILTINS = compiled.get_special_object(self, 'BUILTINS')
|
self.BUILTINS = compiled.get_special_object(self, 'BUILTINS')
|
||||||
|
|
||||||
|
def reset_recursion_limitations(self):
|
||||||
|
self.recursion_detector = recursion.RecursionDetector(self)
|
||||||
|
self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self)
|
||||||
|
|
||||||
def wrap(self, element):
|
def wrap(self, element):
|
||||||
if isinstance(element, tree.Class):
|
if isinstance(element, tree.Class):
|
||||||
return er.Class(self, element)
|
return er.Class(self, element)
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ CODES = {
|
|||||||
'type-error-not-iterable': (11, TypeError, None),
|
'type-error-not-iterable': (11, TypeError, None),
|
||||||
'type-error-isinstance': (12, TypeError, None),
|
'type-error-isinstance': (12, TypeError, None),
|
||||||
'type-error-not-subscriptable': (13, TypeError, None),
|
'type-error-not-subscriptable': (13, TypeError, None),
|
||||||
'value-error-too-many-values': (13, ValueError, None),
|
'value-error-too-many-values': (14, ValueError, None),
|
||||||
'value-error-too-few-values': (13, ValueError, None),
|
'value-error-too-few-values': (15, ValueError, None),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -263,9 +263,7 @@ class Array(IterableWrapper, ArrayMixin):
|
|||||||
for _ in types:
|
for _ in types:
|
||||||
yield types
|
yield types
|
||||||
else:
|
else:
|
||||||
iterate = self._items()
|
for value in self._items():
|
||||||
|
|
||||||
for value in iterate:
|
|
||||||
yield self._evaluator.eval_element(value)
|
yield self._evaluator.eval_element(value)
|
||||||
|
|
||||||
additions = check_array_additions(self._evaluator, self)
|
additions = check_array_additions(self._evaluator, self)
|
||||||
@@ -392,8 +390,8 @@ def unpack_tuple_to_dict(evaluator, types, exprlist):
|
|||||||
'testlist_star_expr'):
|
'testlist_star_expr'):
|
||||||
dct = {}
|
dct = {}
|
||||||
parts = iter(exprlist.children[::2])
|
parts = iter(exprlist.children[::2])
|
||||||
n = 1
|
n = 0
|
||||||
for iter_types in enumerate(py__iter__(evaluator, types, exprlist)):
|
for iter_types in py__iter__(evaluator, types, exprlist):
|
||||||
n += 1
|
n += 1
|
||||||
try:
|
try:
|
||||||
part = next(parts)
|
part = next(parts)
|
||||||
@@ -403,7 +401,7 @@ def unpack_tuple_to_dict(evaluator, types, exprlist):
|
|||||||
else:
|
else:
|
||||||
dct.update(unpack_tuple_to_dict(evaluator, iter_types, part))
|
dct.update(unpack_tuple_to_dict(evaluator, iter_types, part))
|
||||||
has_parts = next(parts, None)
|
has_parts = next(parts, None)
|
||||||
if has_parts is not None:
|
if n > 0 and has_parts is not None:
|
||||||
analysis.add(evaluator, 'value-error-too-few-values', has_parts,
|
analysis.add(evaluator, 'value-error-too-few-values', has_parts,
|
||||||
message="ValueError: need more than %s values to unpack" % n)
|
message="ValueError: need more than %s values to unpack" % n)
|
||||||
return dct
|
return dct
|
||||||
|
|||||||
@@ -372,7 +372,6 @@ def get_params(evaluator, func, var_args):
|
|||||||
# print('\t\tnonkw', non_kw_param.parent.var_args.argument_node, )
|
# print('\t\tnonkw', non_kw_param.parent.var_args.argument_node, )
|
||||||
if origin_args not in [f.parent.parent for f in first_values]:
|
if origin_args not in [f.parent.parent for f in first_values]:
|
||||||
continue
|
continue
|
||||||
print(v)
|
|
||||||
analysis.add(evaluator, 'type-error-too-many-arguments',
|
analysis.add(evaluator, 'type-error-too-many-arguments',
|
||||||
v, message=m)
|
v, message=m)
|
||||||
return param_names
|
return param_names
|
||||||
|
|||||||
@@ -12,3 +12,7 @@ for x in dct:
|
|||||||
#! 4 type-error-not-iterable
|
#! 4 type-error-not-iterable
|
||||||
for x, y in dct:
|
for x, y in dct:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Shouldn't cause issues, because if there are no types (or we don't know what
|
||||||
|
# the types are, we should just ignore it.
|
||||||
|
a, b = []
|
||||||
|
|||||||
Reference in New Issue
Block a user