mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-25 05:07:12 +08:00
Fix side effect issues with predefined names and lazy contexts.
This commit is contained in:
@@ -304,7 +304,10 @@ class Script(object):
|
|||||||
if call_signature_details is None:
|
if call_signature_details is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
context = self._evaluator.create_context(call_signature_details.bracket_leaf)
|
context = self._evaluator.create_context(
|
||||||
|
self._get_module(),
|
||||||
|
call_signature_details.bracket_leaf
|
||||||
|
)
|
||||||
with common.scale_speed_settings(settings.scale_call_signatures):
|
with common.scale_speed_settings(settings.scale_call_signatures):
|
||||||
definitions = helpers.cache_call_signatures(
|
definitions = helpers.cache_call_signatures(
|
||||||
self._evaluator,
|
self._evaluator,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ def get_call_signature_param_names(call_signatures):
|
|||||||
# add named params
|
# add named params
|
||||||
for call_sig in call_signatures:
|
for call_sig in call_signatures:
|
||||||
# Allow protected access, because it's a public API.
|
# Allow protected access, because it's a public API.
|
||||||
module = call_sig._name.get_parent_until()
|
module = call_sig._name.get_root_context()
|
||||||
# Compiled modules typically don't allow keyword arguments.
|
# Compiled modules typically don't allow keyword arguments.
|
||||||
if not isinstance(module, compiled.CompiledObject):
|
if not isinstance(module, compiled.CompiledObject):
|
||||||
for p in call_sig.params:
|
for p in call_sig.params:
|
||||||
|
|||||||
@@ -99,9 +99,17 @@ class LazyTreeContext(AbstractLazyContext):
|
|||||||
def __init__(self, context, node):
|
def __init__(self, context, node):
|
||||||
super(LazyTreeContext, self).__init__(node)
|
super(LazyTreeContext, self).__init__(node)
|
||||||
self._context = context
|
self._context = context
|
||||||
|
# We need to save the predefined names. It's an unfortunate side effect
|
||||||
|
# that needs to be tracked otherwise results will be wrong.
|
||||||
|
self._predefined_names = dict(context.predefined_names)
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
return self._context.eval_node(self.data)
|
old, self._context.predefined_names = \
|
||||||
|
self._context.predefined_names, self._predefined_names
|
||||||
|
try:
|
||||||
|
return self._context.eval_node(self.data)
|
||||||
|
finally:
|
||||||
|
self._context.predefined_names = old
|
||||||
|
|
||||||
|
|
||||||
def get_merged_lazy_context(lazy_contexts):
|
def get_merged_lazy_context(lazy_contexts):
|
||||||
|
|||||||
Reference in New Issue
Block a user