mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
parent_value -> parent_context
This commit is contained in:
@@ -360,7 +360,7 @@ class BaseDefinition(object):
|
||||
if not self._name.is_value_name:
|
||||
return None
|
||||
|
||||
value = self._name.parent_value
|
||||
value = self._name.parent_context
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
class BaseValue(object):
|
||||
def __init__(self, infer_state, parent_value=None):
|
||||
def __init__(self, infer_state, parent_context=None):
|
||||
self.infer_state = infer_state
|
||||
self.parent_value = parent_value
|
||||
self.parent_context = parent_context
|
||||
|
||||
def get_root_value(self):
|
||||
value = self
|
||||
while True:
|
||||
if value.parent_value is None:
|
||||
if value.parent_context is None:
|
||||
return value
|
||||
value = value.parent_value
|
||||
value = value.parent_context
|
||||
|
||||
|
||||
class BaseValueSet(object):
|
||||
|
||||
@@ -390,13 +390,13 @@ class InferState(object):
|
||||
|
||||
is_funcdef = scope_node.type in ('funcdef', 'lambdef')
|
||||
parent_scope = parser_utils.get_parent_scope(scope_node)
|
||||
parent_value = from_scope_node(parent_scope)
|
||||
parent_context = from_scope_node(parent_scope)
|
||||
|
||||
if is_funcdef:
|
||||
func = FunctionValue.from_value(parent_value, scope_node)
|
||||
if parent_value.is_class():
|
||||
func = FunctionValue.from_value(parent_context, scope_node)
|
||||
if parent_context.is_class():
|
||||
instance = AnonymousInstance(
|
||||
self, parent_value.parent_value, parent_value)
|
||||
self, parent_context.parent_context, parent_context)
|
||||
func = BoundMethod(
|
||||
instance=instance,
|
||||
function=func
|
||||
@@ -406,11 +406,11 @@ class InferState(object):
|
||||
return func.get_function_execution()
|
||||
return func
|
||||
elif scope_node.type == 'classdef':
|
||||
return ClassValue(self, parent_value, scope_node)
|
||||
return ClassValue(self, parent_context, scope_node)
|
||||
elif scope_node.type in ('comp_for', 'sync_comp_for'):
|
||||
if node.start_pos >= scope_node.children[-1].start_pos:
|
||||
return parent_value
|
||||
return CompForValue.from_comp_for(parent_value, scope_node)
|
||||
return parent_context
|
||||
return CompForValue.from_comp_for(parent_context, scope_node)
|
||||
raise Exception("There's a scope that was not managed.")
|
||||
|
||||
base_node = base_value.tree_node
|
||||
|
||||
@@ -124,7 +124,7 @@ def add_attribute_error(name_value, lookup_value, name):
|
||||
for n in slot_names:
|
||||
# TODO do we even get here?
|
||||
if isinstance(name, CompiledInstanceName) and \
|
||||
n.parent_value.obj == object:
|
||||
n.parent_context.obj == object:
|
||||
typ = Warning
|
||||
break
|
||||
|
||||
@@ -149,7 +149,7 @@ def _check_for_exception_catch(node_value, jedi_name, exception, payload=None):
|
||||
|
||||
for python_cls in exception.mro():
|
||||
if cls.py__name__() == python_cls.__name__ \
|
||||
and cls.parent_value == cls.infer_state.builtins_module:
|
||||
and cls.parent_context == cls.infer_state.builtins_module:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ class HelperValueMixin(object):
|
||||
def get_root_value(self):
|
||||
value = self
|
||||
while True:
|
||||
if value.parent_value is None:
|
||||
if value.parent_context is None:
|
||||
return value
|
||||
value = value.parent_value
|
||||
value = value.parent_context
|
||||
|
||||
@classmethod
|
||||
@infer_state_as_method_param_cache()
|
||||
@@ -211,7 +211,7 @@ class Value(HelperValueMixin, BaseValue):
|
||||
|
||||
def is_stub(self):
|
||||
# The root value knows if it's a stub or not.
|
||||
return self.parent_value.is_stub()
|
||||
return self.parent_context.is_stub()
|
||||
|
||||
|
||||
def iterate_values(values, valueualized_node=None, is_async=False):
|
||||
@@ -271,8 +271,8 @@ class ValueWrapper(_ValueWrapperBase):
|
||||
|
||||
|
||||
class TreeValue(Value):
|
||||
def __init__(self, infer_state, parent_value, tree_node):
|
||||
super(TreeValue, self).__init__(infer_state, parent_value)
|
||||
def __init__(self, infer_state, parent_context, tree_node):
|
||||
super(TreeValue, self).__init__(infer_state, parent_context)
|
||||
self.predefined_names = {}
|
||||
self.tree_node = tree_node
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ def compiled_objects_cache(attribute_name):
|
||||
Caching the id has the advantage that an object doesn't need to be
|
||||
hashable.
|
||||
"""
|
||||
def wrapper(infer_state, obj, parent_value=None):
|
||||
def wrapper(infer_state, obj, parent_context=None):
|
||||
cache = getattr(infer_state, attribute_name)
|
||||
# Do a very cheap form of caching here.
|
||||
key = id(obj)
|
||||
@@ -119,11 +119,11 @@ def compiled_objects_cache(attribute_name):
|
||||
except KeyError:
|
||||
# TODO wuaaaarrghhhhhhhh
|
||||
if attribute_name == 'mixed_cache':
|
||||
result = func(infer_state, obj, parent_value)
|
||||
result = func(infer_state, obj, parent_context)
|
||||
else:
|
||||
result = func(infer_state, obj)
|
||||
# Need to cache all of them, otherwise the id could be overwritten.
|
||||
cache[key] = result, obj, parent_value
|
||||
cache[key] = result, obj, parent_context
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ class MixedName(compiled.CompiledName):
|
||||
@underscore_memoization
|
||||
def infer(self):
|
||||
# TODO use logic from compiled.CompiledObjectFilter
|
||||
access_paths = self.parent_value.access_handle.getattr_paths(
|
||||
access_paths = self.parent_context.access_handle.getattr_paths(
|
||||
self.string_name,
|
||||
default=None
|
||||
)
|
||||
@@ -105,7 +105,7 @@ class MixedName(compiled.CompiledName):
|
||||
values = [None]
|
||||
for access in access_paths:
|
||||
values = ValueSet.from_sets(
|
||||
_create(self._infer_state, access, parent_value=c)
|
||||
_create(self._infer_state, access, parent_context=c)
|
||||
if c is None or isinstance(c, MixedObject)
|
||||
else ValueSet({create_cached_compiled_object(c.infer_state, access, c)})
|
||||
for c in values
|
||||
@@ -230,11 +230,11 @@ def _find_syntax_node_name(infer_state, python_object):
|
||||
|
||||
|
||||
@compiled_objects_cache('mixed_cache')
|
||||
def _create(infer_state, access_handle, parent_value, *args):
|
||||
def _create(infer_state, access_handle, parent_context, *args):
|
||||
compiled_object = create_cached_compiled_object(
|
||||
infer_state,
|
||||
access_handle,
|
||||
parent_value=parent_value and parent_value.compiled_object
|
||||
parent_context=parent_context and parent_context.compiled_object
|
||||
)
|
||||
|
||||
# TODO accessing this is bad, but it probably doesn't matter that much,
|
||||
@@ -252,7 +252,7 @@ def _create(infer_state, access_handle, parent_value, *args):
|
||||
else:
|
||||
module_node, tree_node, file_io, code_lines = result
|
||||
|
||||
if parent_value is None:
|
||||
if parent_context is None:
|
||||
# TODO this __name__ is probably wrong.
|
||||
name = compiled_object.get_root_value().py__name__()
|
||||
string_names = tuple(name.split('.'))
|
||||
@@ -266,12 +266,12 @@ def _create(infer_state, access_handle, parent_value, *args):
|
||||
if name is not None:
|
||||
infer_state.module_cache.add(string_names, ValueSet([module_value]))
|
||||
else:
|
||||
if parent_value.tree_node.get_root_node() != module_node:
|
||||
if parent_context.tree_node.get_root_node() != module_node:
|
||||
# This happens e.g. when __module__ is wrong, or when using
|
||||
# TypeVar('foo'), where Jedi uses 'foo' as the name and
|
||||
# Python's TypeVar('foo').__module__ will be typing.
|
||||
return ValueSet({compiled_object})
|
||||
module_value = parent_value.get_root_value()
|
||||
module_value = parent_context.get_root_value()
|
||||
|
||||
tree_values = ValueSet({
|
||||
module_value.create_value(
|
||||
|
||||
@@ -41,8 +41,8 @@ class CheckAttribute(object):
|
||||
|
||||
|
||||
class CompiledObject(Value):
|
||||
def __init__(self, infer_state, access_handle, parent_value=None):
|
||||
super(CompiledObject, self).__init__(infer_state, parent_value)
|
||||
def __init__(self, infer_state, access_handle, parent_context=None):
|
||||
super(CompiledObject, self).__init__(infer_state, parent_context)
|
||||
self.access_handle = access_handle
|
||||
|
||||
def py__call__(self, arguments):
|
||||
@@ -59,7 +59,7 @@ class CompiledObject(Value):
|
||||
if self.access_handle.is_class():
|
||||
from jedi.inference.value import CompiledInstance
|
||||
return ValueSet([
|
||||
CompiledInstance(self.infer_state, self.parent_value, self, arguments)
|
||||
CompiledInstance(self.infer_state, self.parent_context, self, arguments)
|
||||
])
|
||||
else:
|
||||
return ValueSet(self._execute_function(arguments))
|
||||
@@ -269,18 +269,18 @@ class CompiledObject(Value):
|
||||
|
||||
|
||||
class CompiledName(AbstractNameDefinition):
|
||||
def __init__(self, infer_state, parent_value, name):
|
||||
def __init__(self, infer_state, parent_context, name):
|
||||
self._infer_state = infer_state
|
||||
self.parent_value = parent_value
|
||||
self.parent_context = parent_context
|
||||
self.string_name = name
|
||||
|
||||
def _get_qualified_names(self):
|
||||
parent_qualified_names = self.parent_value.get_qualified_names()
|
||||
parent_qualified_names = self.parent_context.get_qualified_names()
|
||||
return parent_qualified_names + (self.string_name,)
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
name = self.parent_value.name # __name__ is not defined all the time
|
||||
name = self.parent_context.name # __name__ is not defined all the time
|
||||
except AttributeError:
|
||||
name = None
|
||||
return '<%s: (%s).%s>' % (self.__class__.__name__, name, self.string_name)
|
||||
@@ -296,13 +296,13 @@ class CompiledName(AbstractNameDefinition):
|
||||
@underscore_memoization
|
||||
def infer(self):
|
||||
return ValueSet([_create_from_name(
|
||||
self._infer_state, self.parent_value, self.string_name
|
||||
self._infer_state, self.parent_context, self.string_name
|
||||
)])
|
||||
|
||||
|
||||
class SignatureParamName(ParamNameInterface, AbstractNameDefinition):
|
||||
def __init__(self, compiled_obj, signature_param):
|
||||
self.parent_value = compiled_obj.parent_value
|
||||
self.parent_context = compiled_obj.parent_context
|
||||
self._signature_param = signature_param
|
||||
|
||||
@property
|
||||
@@ -322,7 +322,7 @@ class SignatureParamName(ParamNameInterface, AbstractNameDefinition):
|
||||
|
||||
def infer(self):
|
||||
p = self._signature_param
|
||||
infer_state = self.parent_value.infer_state
|
||||
infer_state = self.parent_context.infer_state
|
||||
values = NO_VALUES
|
||||
if p.has_default:
|
||||
values = ValueSet([create_from_access_path(infer_state, p.default)])
|
||||
@@ -334,7 +334,7 @@ class SignatureParamName(ParamNameInterface, AbstractNameDefinition):
|
||||
|
||||
class UnresolvableParamName(ParamNameInterface, AbstractNameDefinition):
|
||||
def __init__(self, compiled_obj, name, default):
|
||||
self.parent_value = compiled_obj.parent_value
|
||||
self.parent_context = compiled_obj.parent_context
|
||||
self.string_name = name
|
||||
self._default = default
|
||||
|
||||
@@ -355,7 +355,7 @@ class CompiledValueName(ValueNameMixin, AbstractNameDefinition):
|
||||
def __init__(self, value, name):
|
||||
self.string_name = name
|
||||
self._value = value
|
||||
self.parent_value = value.parent_value
|
||||
self.parent_context = value.parent_context
|
||||
|
||||
|
||||
class EmptyCompiledName(AbstractNameDefinition):
|
||||
@@ -365,7 +365,7 @@ class EmptyCompiledName(AbstractNameDefinition):
|
||||
nothing.
|
||||
"""
|
||||
def __init__(self, infer_state, name):
|
||||
self.parent_value = infer_state.builtins_module
|
||||
self.parent_context = infer_state.builtins_module
|
||||
self.string_name = name
|
||||
|
||||
def infer(self):
|
||||
@@ -509,33 +509,33 @@ def _parse_function_doc(doc):
|
||||
|
||||
def _create_from_name(infer_state, compiled_object, name):
|
||||
access_paths = compiled_object.access_handle.getattr_paths(name, default=None)
|
||||
parent_value = compiled_object
|
||||
if parent_value.is_class():
|
||||
parent_value = parent_value.parent_value
|
||||
parent_context = compiled_object
|
||||
if parent_context.is_class():
|
||||
parent_context = parent_context.parent_context
|
||||
|
||||
value = None
|
||||
for access_path in access_paths:
|
||||
value = create_cached_compiled_object(
|
||||
infer_state, access_path, parent_value=value
|
||||
infer_state, access_path, parent_context=value
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
def _normalize_create_args(func):
|
||||
"""The cache doesn't care about keyword vs. normal args."""
|
||||
def wrapper(infer_state, obj, parent_value=None):
|
||||
return func(infer_state, obj, parent_value)
|
||||
def wrapper(infer_state, obj, parent_context=None):
|
||||
return func(infer_state, obj, parent_context)
|
||||
return wrapper
|
||||
|
||||
|
||||
def create_from_access_path(infer_state, access_path):
|
||||
parent_value = None
|
||||
parent_context = None
|
||||
for name, access in access_path.accesses:
|
||||
parent_value = create_cached_compiled_object(infer_state, access, parent_value)
|
||||
return parent_value
|
||||
parent_context = create_cached_compiled_object(infer_state, access, parent_context)
|
||||
return parent_context
|
||||
|
||||
|
||||
@_normalize_create_args
|
||||
@infer_state_function_cache()
|
||||
def create_cached_compiled_object(infer_state, access_handle, parent_value):
|
||||
return CompiledObject(infer_state, access_handle, parent_value)
|
||||
def create_cached_compiled_object(infer_state, access_handle, parent_context):
|
||||
return CompiledObject(infer_state, access_handle, parent_context)
|
||||
|
||||
@@ -189,7 +189,7 @@ def _check_name_for_execution(infer_state, value, compare_node, name, trailer):
|
||||
if value_node.type == 'classdef':
|
||||
created_instance = instance.TreeInstance(
|
||||
infer_state,
|
||||
v.parent_value,
|
||||
v.parent_context,
|
||||
v,
|
||||
args
|
||||
)
|
||||
@@ -203,12 +203,12 @@ def _check_name_for_execution(infer_state, value, compare_node, name, trailer):
|
||||
if compare_node == value_node:
|
||||
for func_execution in create_func_excs():
|
||||
yield func_execution
|
||||
elif isinstance(v.parent_value, FunctionExecutionValue) and \
|
||||
elif isinstance(v.parent_context, FunctionExecutionValue) and \
|
||||
compare_node.type == 'funcdef':
|
||||
# Here we're trying to find decorators by checking the first
|
||||
# parameter. It's not very generic though. Should find a better
|
||||
# solution that also applies to nested decorators.
|
||||
params, _ = v.parent_value.get_executed_params_and_issues()
|
||||
params, _ = v.parent_context.get_executed_params_and_issues()
|
||||
if len(params) != 1:
|
||||
continue
|
||||
values = params[0].infer()
|
||||
|
||||
@@ -238,14 +238,14 @@ class _BuiltinMappedMethod(Value):
|
||||
def __init__(self, builtin_value, method, builtin_func):
|
||||
super(_BuiltinMappedMethod, self).__init__(
|
||||
builtin_value.infer_state,
|
||||
parent_value=builtin_value
|
||||
parent_context=builtin_value
|
||||
)
|
||||
self._method = method
|
||||
self._builtin_func = builtin_func
|
||||
|
||||
def py__call__(self, arguments):
|
||||
# TODO add TypeError if params are given/or not correct.
|
||||
return self._method(self.parent_value)
|
||||
return self._method(self.parent_context)
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self._builtin_func, name)
|
||||
@@ -259,13 +259,13 @@ class SpecialMethodFilter(DictFilter):
|
||||
class SpecialMethodName(AbstractNameDefinition):
|
||||
api_type = u'function'
|
||||
|
||||
def __init__(self, parent_value, string_name, value, builtin_value):
|
||||
def __init__(self, parent_context, string_name, value, builtin_value):
|
||||
callable_, python_version = value
|
||||
if python_version is not None and \
|
||||
python_version != parent_value.infer_state.environment.version_info.major:
|
||||
python_version != parent_context.infer_state.environment.version_info.major:
|
||||
raise KeyError
|
||||
|
||||
self.parent_value = parent_value
|
||||
self.parent_context = parent_context
|
||||
self.string_name = string_name
|
||||
self._callable = callable_
|
||||
self._builtin_value = builtin_value
|
||||
@@ -282,7 +282,7 @@ class SpecialMethodFilter(DictFilter):
|
||||
continue
|
||||
break
|
||||
return ValueSet([
|
||||
_BuiltinMappedMethod(self.parent_value, self._callable, builtin_func)
|
||||
_BuiltinMappedMethod(self.parent_context, self._callable, builtin_func)
|
||||
])
|
||||
|
||||
def __init__(self, value, dct, builtin_value):
|
||||
@@ -406,7 +406,7 @@ def get_global_filters(infer_state, value, until_position, origin_scope):
|
||||
# The position should be reset if the current scope is a function.
|
||||
until_position = None
|
||||
|
||||
value = value.parent_value
|
||||
value = value.parent_context
|
||||
|
||||
# Add builtins to the global scope.
|
||||
yield next(infer_state.builtins_module.get_filters())
|
||||
|
||||
@@ -37,7 +37,7 @@ _PROXY_TYPES = 'Optional Union ClassVar'.split()
|
||||
|
||||
class TypingName(AbstractTreeName):
|
||||
def __init__(self, value, other_name):
|
||||
super(TypingName, self).__init__(value.parent_value, other_name.tree_name)
|
||||
super(TypingName, self).__init__(value.parent_context, other_name.tree_name)
|
||||
self._value = value
|
||||
|
||||
def infer(self):
|
||||
@@ -45,8 +45,8 @@ class TypingName(AbstractTreeName):
|
||||
|
||||
|
||||
class _BaseTypingValue(Value):
|
||||
def __init__(self, infer_state, parent_value, tree_name):
|
||||
super(_BaseTypingValue, self).__init__(infer_state, parent_value)
|
||||
def __init__(self, infer_state, parent_context, tree_name):
|
||||
super(_BaseTypingValue, self).__init__(infer_state, parent_context)
|
||||
self._tree_name = tree_name
|
||||
|
||||
@property
|
||||
@@ -87,39 +87,39 @@ class TypingModuleName(NameWrapper):
|
||||
|
||||
def _remap(self):
|
||||
name = self.string_name
|
||||
infer_state = self.parent_value.infer_state
|
||||
infer_state = self.parent_context.infer_state
|
||||
try:
|
||||
actual = _TYPE_ALIAS_TYPES[name]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
yield TypeAlias.create_cached(infer_state, self.parent_value, self.tree_name, actual)
|
||||
yield TypeAlias.create_cached(infer_state, self.parent_context, self.tree_name, actual)
|
||||
return
|
||||
|
||||
if name in _PROXY_CLASS_TYPES:
|
||||
yield TypingClassValue.create_cached(infer_state, self.parent_value, self.tree_name)
|
||||
yield TypingClassValue.create_cached(infer_state, self.parent_context, self.tree_name)
|
||||
elif name in _PROXY_TYPES:
|
||||
yield TypingValue.create_cached(infer_state, self.parent_value, self.tree_name)
|
||||
yield TypingValue.create_cached(infer_state, self.parent_context, self.tree_name)
|
||||
elif name == 'runtime':
|
||||
# We don't want anything here, not sure what this function is
|
||||
# supposed to do, since it just appears in the stubs and shouldn't
|
||||
# have any effects there (because it's never executed).
|
||||
return
|
||||
elif name == 'TypeVar':
|
||||
yield TypeVarClass.create_cached(infer_state, self.parent_value, self.tree_name)
|
||||
yield TypeVarClass.create_cached(infer_state, self.parent_context, self.tree_name)
|
||||
elif name == 'Any':
|
||||
yield Any.create_cached(infer_state, self.parent_value, self.tree_name)
|
||||
yield Any.create_cached(infer_state, self.parent_context, self.tree_name)
|
||||
elif name == 'TYPE_CHECKING':
|
||||
# This is needed for e.g. imports that are only available for type
|
||||
# checking or are in cycles. The user can then check this variable.
|
||||
yield builtin_from_name(infer_state, u'True')
|
||||
elif name == 'overload':
|
||||
yield OverloadFunction.create_cached(infer_state, self.parent_value, self.tree_name)
|
||||
yield OverloadFunction.create_cached(infer_state, self.parent_context, self.tree_name)
|
||||
elif name == 'NewType':
|
||||
yield NewTypeFunction.create_cached(infer_state, self.parent_value, self.tree_name)
|
||||
yield NewTypeFunction.create_cached(infer_state, self.parent_context, self.tree_name)
|
||||
elif name == 'cast':
|
||||
# TODO implement cast
|
||||
yield CastFunction.create_cached(infer_state, self.parent_value, self.tree_name)
|
||||
yield CastFunction.create_cached(infer_state, self.parent_context, self.tree_name)
|
||||
elif name == 'TypedDict':
|
||||
# TODO doesn't even exist in typeshed/typing.py, yet. But will be
|
||||
# added soon.
|
||||
@@ -139,8 +139,8 @@ class TypingModuleFilterWrapper(FilterWrapper):
|
||||
|
||||
|
||||
class _WithIndexBase(_BaseTypingValue):
|
||||
def __init__(self, infer_state, parent_value, name, index_value, value_of_index):
|
||||
super(_WithIndexBase, self).__init__(infer_state, parent_value, name)
|
||||
def __init__(self, infer_state, parent_context, name, index_value, value_of_index):
|
||||
super(_WithIndexBase, self).__init__(infer_state, parent_context, name)
|
||||
self._index_value = index_value
|
||||
self._value_of_index = value_of_index
|
||||
|
||||
@@ -175,7 +175,7 @@ class TypingValueWithIndex(_WithIndexBase):
|
||||
cls = globals()[string_name]
|
||||
return ValueSet([cls(
|
||||
self.infer_state,
|
||||
self.parent_value,
|
||||
self.parent_context,
|
||||
self._tree_name,
|
||||
self._index_value,
|
||||
self._value_of_index
|
||||
@@ -195,7 +195,7 @@ class TypingValue(_BaseTypingValue):
|
||||
return ValueSet(
|
||||
self.index_class.create_cached(
|
||||
self.infer_state,
|
||||
self.parent_value,
|
||||
self.parent_context,
|
||||
self._tree_name,
|
||||
index_value,
|
||||
value_of_index=valueualized_node.value)
|
||||
@@ -245,9 +245,9 @@ def _iter_over_arguments(maybe_tuple_value, defining_value):
|
||||
|
||||
|
||||
class TypeAlias(LazyValueWrapper):
|
||||
def __init__(self, parent_value, origin_tree_name, actual):
|
||||
self.infer_state = parent_value.infer_state
|
||||
self.parent_value = parent_value
|
||||
def __init__(self, parent_context, origin_tree_name, actual):
|
||||
self.infer_state = parent_context.infer_state
|
||||
self.parent_context = parent_context
|
||||
self._origin_tree_name = origin_tree_name
|
||||
self._actual = actual # e.g. builtins.list
|
||||
|
||||
@@ -359,7 +359,7 @@ class TypeVarClass(_BaseTypingValue):
|
||||
|
||||
return ValueSet([TypeVar.create_cached(
|
||||
self.infer_state,
|
||||
self.parent_value,
|
||||
self.parent_context,
|
||||
self._tree_name,
|
||||
var_name,
|
||||
unpacked
|
||||
@@ -391,8 +391,8 @@ class TypeVarClass(_BaseTypingValue):
|
||||
|
||||
|
||||
class TypeVar(_BaseTypingValue):
|
||||
def __init__(self, infer_state, parent_value, tree_name, var_name, unpacked_args):
|
||||
super(TypeVar, self).__init__(infer_state, parent_value, tree_name)
|
||||
def __init__(self, infer_state, parent_context, tree_name, var_name, unpacked_args):
|
||||
super(TypeVar, self).__init__(infer_state, parent_context, tree_name)
|
||||
self._var_name = var_name
|
||||
|
||||
self._constraints_lazy_values = []
|
||||
@@ -477,8 +477,8 @@ class NewTypeFunction(_BaseTypingValue):
|
||||
|
||||
|
||||
class NewType(Value):
|
||||
def __init__(self, infer_state, parent_value, tree_node, type_value_set):
|
||||
super(NewType, self).__init__(infer_state, parent_value)
|
||||
def __init__(self, infer_state, parent_context, tree_node, type_value_set):
|
||||
super(NewType, self).__init__(infer_state, parent_context)
|
||||
self._type_value_set = type_value_set
|
||||
self.tree_node = tree_node
|
||||
|
||||
@@ -498,7 +498,7 @@ class BoundTypeVarName(AbstractNameDefinition):
|
||||
"""
|
||||
def __init__(self, type_var, value_set):
|
||||
self._type_var = type_var
|
||||
self.parent_value = type_var.parent_value
|
||||
self.parent_context = type_var.parent_context
|
||||
self._value_set = value_set
|
||||
|
||||
def infer(self):
|
||||
|
||||
@@ -10,7 +10,7 @@ from jedi.cache import memoize_method
|
||||
class AbstractNameDefinition(object):
|
||||
start_pos = None
|
||||
string_name = None
|
||||
parent_value = None
|
||||
parent_context = None
|
||||
tree_name = None
|
||||
is_value_name = True
|
||||
"""
|
||||
@@ -42,7 +42,7 @@ class AbstractNameDefinition(object):
|
||||
return None
|
||||
|
||||
def get_root_value(self):
|
||||
return self.parent_value.get_root_value()
|
||||
return self.parent_context.get_root_value()
|
||||
|
||||
def __repr__(self):
|
||||
if self.start_pos is None:
|
||||
@@ -55,7 +55,7 @@ class AbstractNameDefinition(object):
|
||||
|
||||
@property
|
||||
def api_type(self):
|
||||
return self.parent_value.api_type
|
||||
return self.parent_context.api_type
|
||||
|
||||
|
||||
class AbstractArbitraryName(AbstractNameDefinition):
|
||||
@@ -69,15 +69,15 @@ class AbstractArbitraryName(AbstractNameDefinition):
|
||||
def __init__(self, infer_state, string):
|
||||
self.infer_state = infer_state
|
||||
self.string_name = string
|
||||
self.parent_value = infer_state.builtins_module
|
||||
self.parent_context = infer_state.builtins_module
|
||||
|
||||
def infer(self):
|
||||
return NO_VALUES
|
||||
|
||||
|
||||
class AbstractTreeName(AbstractNameDefinition):
|
||||
def __init__(self, parent_value, tree_name):
|
||||
self.parent_value = parent_value
|
||||
def __init__(self, parent_context, tree_name):
|
||||
self.parent_context = parent_context
|
||||
self.tree_name = tree_name
|
||||
|
||||
def get_qualified_names(self, include_module_names=False):
|
||||
@@ -97,13 +97,13 @@ class AbstractTreeName(AbstractNameDefinition):
|
||||
return super(AbstractTreeName, self).get_qualified_names(include_module_names)
|
||||
|
||||
def _get_qualified_names(self):
|
||||
parent_names = self.parent_value.get_qualified_names()
|
||||
parent_names = self.parent_context.get_qualified_names()
|
||||
if parent_names is None:
|
||||
return None
|
||||
return parent_names + (self.tree_name.value,)
|
||||
|
||||
def goto(self, **kwargs):
|
||||
return self.parent_value.infer_state.goto(self.parent_value, self.tree_name, **kwargs)
|
||||
return self.parent_context.infer_state.goto(self.parent_context, self.tree_name, **kwargs)
|
||||
|
||||
def is_import(self):
|
||||
imp = search_ancestor(self.tree_name, 'import_from', 'import_name')
|
||||
@@ -126,7 +126,7 @@ class ValueNameMixin(object):
|
||||
return self._value.get_qualified_names()
|
||||
|
||||
def get_root_value(self):
|
||||
if self.parent_value is None: # A module
|
||||
if self.parent_context is None: # A module
|
||||
return self._value
|
||||
return super(ValueNameMixin, self).get_root_value()
|
||||
|
||||
@@ -137,7 +137,7 @@ class ValueNameMixin(object):
|
||||
|
||||
class ValueName(ValueNameMixin, AbstractTreeName):
|
||||
def __init__(self, value, tree_name):
|
||||
super(ValueName, self).__init__(value.parent_value, tree_name)
|
||||
super(ValueName, self).__init__(value.parent_context, tree_name)
|
||||
self._value = value
|
||||
|
||||
def goto(self):
|
||||
@@ -156,7 +156,7 @@ class TreeNameDefinition(AbstractTreeName):
|
||||
def infer(self):
|
||||
# Refactor this, should probably be here.
|
||||
from jedi.inference.syntax_tree import tree_name_to_values
|
||||
parent = self.parent_value
|
||||
parent = self.parent_context
|
||||
return tree_name_to_values(parent.infer_state, parent, self.tree_name)
|
||||
|
||||
@property
|
||||
@@ -241,7 +241,7 @@ class ParamName(BaseTreeParamName):
|
||||
node = self.annotation_node
|
||||
if node is None:
|
||||
return NO_VALUES
|
||||
values = self.parent_value.parent_value.infer_node(node)
|
||||
values = self.parent_context.parent_context.infer_node(node)
|
||||
if execute_annotation:
|
||||
values = values.execute_annotation()
|
||||
return values
|
||||
@@ -250,7 +250,7 @@ class ParamName(BaseTreeParamName):
|
||||
node = self.default_node
|
||||
if node is None:
|
||||
return NO_VALUES
|
||||
return self.parent_value.parent_value.infer_node(node)
|
||||
return self.parent_context.parent_context.infer_node(node)
|
||||
|
||||
@property
|
||||
def default_node(self):
|
||||
@@ -297,7 +297,7 @@ class ParamName(BaseTreeParamName):
|
||||
return self.get_param().infer()
|
||||
|
||||
def get_param(self):
|
||||
params, _ = self.parent_value.get_executed_params_and_issues()
|
||||
params, _ = self.parent_context.get_executed_params_and_issues()
|
||||
param_node = search_ancestor(self.tree_name, 'param')
|
||||
return params[param_node.position_index]
|
||||
|
||||
@@ -317,8 +317,8 @@ class ImportName(AbstractNameDefinition):
|
||||
start_pos = (1, 0)
|
||||
_level = 0
|
||||
|
||||
def __init__(self, parent_value, string_name):
|
||||
self._from_module_value = parent_value
|
||||
def __init__(self, parent_context, string_name):
|
||||
self._from_module_value = parent_context
|
||||
self.string_name = string_name
|
||||
|
||||
def get_qualified_names(self, include_module_names=False):
|
||||
@@ -333,7 +333,7 @@ class ImportName(AbstractNameDefinition):
|
||||
return ()
|
||||
|
||||
@property
|
||||
def parent_value(self):
|
||||
def parent_context(self):
|
||||
m = self._from_module_value
|
||||
import_values = self.infer()
|
||||
if not import_values:
|
||||
|
||||
@@ -244,7 +244,7 @@ def _create_default_param(execution_value, param):
|
||||
elif param.default is None:
|
||||
result_arg = LazyUnknownValue()
|
||||
else:
|
||||
result_arg = LazyTreeValue(execution_value.parent_value, param.default)
|
||||
result_arg = LazyTreeValue(execution_value.parent_context, param.default)
|
||||
return ExecutedParam(execution_value, param, result_arg)
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ def _iter_nodes_for_param(param_name):
|
||||
from parso.python.tree import search_ancestor
|
||||
from jedi.inference.arguments import TreeArguments
|
||||
|
||||
execution_value = param_name.parent_value
|
||||
execution_value = param_name.parent_context
|
||||
function_node = execution_value.tree_node
|
||||
module_node = function_node.get_root_node()
|
||||
start = function_node.children[-1].start_pos
|
||||
@@ -56,7 +56,7 @@ def _goes_to_param_name(param_name, value, potential_name):
|
||||
return False
|
||||
from jedi.inference.names import TreeNameDefinition
|
||||
found = TreeNameDefinition(value, potential_name).goto()
|
||||
return any(param_name.parent_value == p.parent_value
|
||||
return any(param_name.parent_context == p.parent_context
|
||||
and param_name.start_pos == p.start_pos
|
||||
for p in found)
|
||||
|
||||
|
||||
@@ -637,7 +637,7 @@ def _apply_decorators(value, node):
|
||||
if node.type == 'classdef':
|
||||
decoratee_value = ClassValue(
|
||||
value.infer_state,
|
||||
parent_value=value,
|
||||
parent_context=value,
|
||||
tree_node=node
|
||||
)
|
||||
else:
|
||||
|
||||
@@ -28,7 +28,7 @@ class LambdaName(AbstractNameDefinition):
|
||||
|
||||
def __init__(self, lambda_value):
|
||||
self._lambda_value = lambda_value
|
||||
self.parent_value = lambda_value.parent_value
|
||||
self.parent_context = lambda_value.parent_context
|
||||
|
||||
@property
|
||||
def start_pos(self):
|
||||
@@ -40,13 +40,13 @@ class LambdaName(AbstractNameDefinition):
|
||||
|
||||
class FunctionAndClassBase(TreeValue):
|
||||
def get_qualified_names(self):
|
||||
if self.parent_value.is_class():
|
||||
n = self.parent_value.get_qualified_names()
|
||||
if self.parent_context.is_class():
|
||||
n = self.parent_context.get_qualified_names()
|
||||
if n is None:
|
||||
# This means that the parent class lives within a function.
|
||||
return None
|
||||
return n + (self.py__name__(),)
|
||||
elif self.parent_value.is_module():
|
||||
elif self.parent_context.is_module():
|
||||
return (self.py__name__(),)
|
||||
else:
|
||||
return None
|
||||
@@ -98,7 +98,7 @@ class FunctionMixin(object):
|
||||
if arguments is None:
|
||||
arguments = AnonymousArguments()
|
||||
|
||||
return FunctionExecutionValue(self.infer_state, self.parent_value, self, arguments)
|
||||
return FunctionExecutionValue(self.infer_state, self.parent_context, self, arguments)
|
||||
|
||||
def get_signatures(self):
|
||||
return [TreeSignature(f) for f in self.get_signature_functions()]
|
||||
@@ -115,21 +115,21 @@ class FunctionValue(use_metaclass(CachedMetaClass, FunctionMixin, FunctionAndCla
|
||||
return MethodValue(
|
||||
value.infer_state,
|
||||
value,
|
||||
parent_value=parent_value,
|
||||
parent_context=parent_context,
|
||||
tree_node=tree_node
|
||||
)
|
||||
else:
|
||||
return cls(
|
||||
value.infer_state,
|
||||
parent_value=parent_value,
|
||||
parent_context=parent_context,
|
||||
tree_node=tree_node
|
||||
)
|
||||
|
||||
overloaded_funcs = list(_find_overload_functions(value, tree_node))
|
||||
|
||||
parent_value = value
|
||||
while parent_value.is_class() or parent_value.is_instance():
|
||||
parent_value = parent_value.parent_value
|
||||
parent_context = value
|
||||
while parent_context.is_class() or parent_context.is_instance():
|
||||
parent_context = parent_context.parent_context
|
||||
|
||||
function = create(tree_node)
|
||||
|
||||
@@ -145,7 +145,7 @@ class FunctionValue(use_metaclass(CachedMetaClass, FunctionMixin, FunctionAndCla
|
||||
return c
|
||||
|
||||
def get_default_param_value(self):
|
||||
return self.parent_value
|
||||
return self.parent_context
|
||||
|
||||
def get_signature_functions(self):
|
||||
return [self]
|
||||
@@ -171,10 +171,10 @@ class MethodValue(FunctionValue):
|
||||
class FunctionExecutionValue(TreeValue):
|
||||
function_execution_filter = FunctionExecutionFilter
|
||||
|
||||
def __init__(self, infer_state, parent_value, function_value, var_args):
|
||||
def __init__(self, infer_state, parent_context, function_value, var_args):
|
||||
super(FunctionExecutionValue, self).__init__(
|
||||
infer_state,
|
||||
parent_value,
|
||||
parent_context,
|
||||
function_value.tree_node,
|
||||
)
|
||||
self.function_value = function_value
|
||||
|
||||
@@ -61,8 +61,8 @@ class AnonymousInstanceArguments(AnonymousArguments):
|
||||
class AbstractInstanceValue(Value):
|
||||
api_type = u'instance'
|
||||
|
||||
def __init__(self, infer_state, parent_value, class_value, var_args):
|
||||
super(AbstractInstanceValue, self).__init__(infer_state, parent_value)
|
||||
def __init__(self, infer_state, parent_context, class_value, var_args):
|
||||
super(AbstractInstanceValue, self).__init__(infer_state, parent_context)
|
||||
# Generated instances are classes that are just generated by self
|
||||
# (No var_args) used.
|
||||
self.class_value = class_value
|
||||
@@ -193,7 +193,7 @@ class AbstractInstanceValue(Value):
|
||||
# TODO is this correct? I think we need to check for functions.
|
||||
if isinstance(name, LazyInstanceClassName):
|
||||
function = FunctionValue.from_value(
|
||||
self.parent_value,
|
||||
self.parent_context,
|
||||
name.tree_name.parent
|
||||
)
|
||||
bound_method = BoundMethod(self, function)
|
||||
@@ -207,19 +207,19 @@ class AbstractInstanceValue(Value):
|
||||
if scope == class_value.tree_node:
|
||||
return class_value
|
||||
else:
|
||||
parent_value = self.create_instance_value(class_value, scope)
|
||||
parent_context = self.create_instance_value(class_value, scope)
|
||||
if scope.type == 'funcdef':
|
||||
func = FunctionValue.from_value(
|
||||
parent_value,
|
||||
parent_context,
|
||||
scope,
|
||||
)
|
||||
bound_method = BoundMethod(self, func)
|
||||
if scope.name.value == '__init__' and parent_value == class_value:
|
||||
if scope.name.value == '__init__' and parent_context == class_value:
|
||||
return bound_method.get_function_execution(self.var_args)
|
||||
else:
|
||||
return bound_method.get_function_execution()
|
||||
elif scope.type == 'classdef':
|
||||
class_value = ClassValue(self.infer_state, parent_value, scope)
|
||||
class_value = ClassValue(self.infer_state, parent_context, scope)
|
||||
return class_value
|
||||
elif scope.type in ('comp_for', 'sync_comp_for'):
|
||||
# Comprehensions currently don't have a special scope in Jedi.
|
||||
@@ -238,9 +238,9 @@ class AbstractInstanceValue(Value):
|
||||
|
||||
|
||||
class CompiledInstance(AbstractInstanceValue):
|
||||
def __init__(self, infer_state, parent_value, class_value, var_args):
|
||||
def __init__(self, infer_state, parent_context, class_value, var_args):
|
||||
self._original_var_args = var_args
|
||||
super(CompiledInstance, self).__init__(infer_state, parent_value, class_value, var_args)
|
||||
super(CompiledInstance, self).__init__(infer_state, parent_context, class_value, var_args)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -258,16 +258,16 @@ class CompiledInstance(AbstractInstanceValue):
|
||||
|
||||
|
||||
class TreeInstance(AbstractInstanceValue):
|
||||
def __init__(self, infer_state, parent_value, class_value, var_args):
|
||||
def __init__(self, infer_state, parent_context, class_value, var_args):
|
||||
# I don't think that dynamic append lookups should happen here. That
|
||||
# sounds more like something that should go to py__iter__.
|
||||
if class_value.py__name__() in ['list', 'set'] \
|
||||
and parent_value.get_root_value() == infer_state.builtins_module:
|
||||
and parent_context.get_root_value() == infer_state.builtins_module:
|
||||
# compare the module path with the builtin name.
|
||||
if settings.dynamic_array_additions:
|
||||
var_args = iterable.get_dynamic_array_instance(self, var_args)
|
||||
|
||||
super(TreeInstance, self).__init__(infer_state, parent_value,
|
||||
super(TreeInstance, self).__init__(infer_state, parent_context,
|
||||
class_value, var_args)
|
||||
self.tree_node = class_value.tree_node
|
||||
|
||||
@@ -313,10 +313,10 @@ class TreeInstance(AbstractInstanceValue):
|
||||
|
||||
|
||||
class AnonymousInstance(TreeInstance):
|
||||
def __init__(self, infer_state, parent_value, class_value):
|
||||
def __init__(self, infer_state, parent_context, class_value):
|
||||
super(AnonymousInstance, self).__init__(
|
||||
infer_state,
|
||||
parent_value,
|
||||
parent_context,
|
||||
class_value,
|
||||
var_args=AnonymousInstanceArguments(self),
|
||||
)
|
||||
@@ -330,7 +330,7 @@ class CompiledInstanceName(compiled.CompiledName):
|
||||
def __init__(self, infer_state, instance, klass, name):
|
||||
super(CompiledInstanceName, self).__init__(
|
||||
infer_state,
|
||||
klass.parent_value,
|
||||
klass.parent_context,
|
||||
name.string_name
|
||||
)
|
||||
self._instance = instance
|
||||
@@ -419,7 +419,7 @@ class CompiledBoundMethod(ValueWrapper):
|
||||
|
||||
class SelfName(TreeNameDefinition):
|
||||
"""
|
||||
This name calculates the parent_value lazily.
|
||||
This name calculates the parent_context lazily.
|
||||
"""
|
||||
def __init__(self, instance, class_value, tree_name):
|
||||
self._instance = instance
|
||||
@@ -427,7 +427,7 @@ class SelfName(TreeNameDefinition):
|
||||
self.tree_name = tree_name
|
||||
|
||||
@property
|
||||
def parent_value(self):
|
||||
def parent_context(self):
|
||||
return self._instance.create_instance_value(self.class_value, self.tree_name)
|
||||
|
||||
|
||||
|
||||
@@ -113,8 +113,8 @@ class Generator(GeneratorBase):
|
||||
|
||||
class CompForValue(TreeValue):
|
||||
@classmethod
|
||||
def from_comp_for(cls, parent_value, comp_for):
|
||||
return cls(parent_value.infer_state, parent_value, comp_for)
|
||||
def from_comp_for(cls, parent_context, comp_for):
|
||||
return cls(parent_context.infer_state, parent_context, comp_for)
|
||||
|
||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
||||
yield ParserTreeFilter(self.infer_state, self)
|
||||
@@ -158,27 +158,27 @@ def comprehension_from_atom(infer_state, value, atom):
|
||||
|
||||
class ComprehensionMixin(object):
|
||||
@infer_state_method_cache()
|
||||
def _get_comp_for_value(self, parent_value, comp_for):
|
||||
return CompForValue.from_comp_for(parent_value, comp_for)
|
||||
def _get_comp_for_value(self, parent_context, comp_for):
|
||||
return CompForValue.from_comp_for(parent_context, comp_for)
|
||||
|
||||
def _nested(self, comp_fors, parent_value=None):
|
||||
def _nested(self, comp_fors, parent_context=None):
|
||||
comp_for = comp_fors[0]
|
||||
|
||||
is_async = comp_for.parent.type == 'comp_for'
|
||||
|
||||
input_node = comp_for.children[3]
|
||||
parent_value = parent_value or self._defining_value
|
||||
input_types = parent_value.infer_node(input_node)
|
||||
parent_context = parent_context or self._defining_value
|
||||
input_types = parent_context.infer_node(input_node)
|
||||
# TODO: simulate await if self.is_async
|
||||
|
||||
cn = ValueualizedNode(parent_value, input_node)
|
||||
cn = ValueualizedNode(parent_context, input_node)
|
||||
iterated = input_types.iterate(cn, is_async=is_async)
|
||||
exprlist = comp_for.children[1]
|
||||
for i, lazy_value in enumerate(iterated):
|
||||
types = lazy_value.infer()
|
||||
dct = unpack_tuple_to_dict(parent_value, types, exprlist)
|
||||
dct = unpack_tuple_to_dict(parent_context, types, exprlist)
|
||||
value_ = self._get_comp_for_value(
|
||||
parent_value,
|
||||
parent_context,
|
||||
comp_for,
|
||||
)
|
||||
with predefine_names(value_, comp_for, dct):
|
||||
|
||||
@@ -63,8 +63,8 @@ def apply_py__get__(value, instance, class_value):
|
||||
|
||||
|
||||
class ClassName(TreeNameDefinition):
|
||||
def __init__(self, parent_value, tree_name, name_value, apply_decorators):
|
||||
super(ClassName, self).__init__(parent_value, tree_name)
|
||||
def __init__(self, parent_context, tree_name, name_value, apply_decorators):
|
||||
super(ClassName, self).__init__(parent_context, tree_name)
|
||||
self._name_value = name_value
|
||||
self._apply_decorators = apply_decorators
|
||||
|
||||
@@ -73,13 +73,13 @@ class ClassName(TreeNameDefinition):
|
||||
# We're using a different value to infer, so we cannot call super().
|
||||
from jedi.inference.syntax_tree import tree_name_to_values
|
||||
inferred = tree_name_to_values(
|
||||
self.parent_value.infer_state, self._name_value, self.tree_name)
|
||||
self.parent_context.infer_state, self._name_value, self.tree_name)
|
||||
|
||||
for result_value in inferred:
|
||||
if self._apply_decorators:
|
||||
for c in apply_py__get__(result_value,
|
||||
instance=None,
|
||||
class_value=self.parent_value):
|
||||
class_value=self.parent_context):
|
||||
yield c
|
||||
else:
|
||||
yield result_value
|
||||
@@ -95,7 +95,7 @@ class ClassFilter(ParserTreeFilter):
|
||||
def _convert_names(self, names):
|
||||
return [
|
||||
self.name_class(
|
||||
parent_value=self.value,
|
||||
parent_context=self.value,
|
||||
tree_name=name,
|
||||
name_value=self._node_value,
|
||||
apply_decorators=not self._is_instance,
|
||||
@@ -141,7 +141,7 @@ class ClassMixin(object):
|
||||
from jedi.inference.value import TreeInstance
|
||||
if arguments is None:
|
||||
arguments = ValuesArguments([])
|
||||
return ValueSet([TreeInstance(self.infer_state, self.parent_value, self, arguments)])
|
||||
return ValueSet([TreeInstance(self.infer_state, self.parent_context, self, arguments)])
|
||||
|
||||
def py__class__(self):
|
||||
return compiled.builtin_from_name(self.infer_state, u'type')
|
||||
@@ -252,7 +252,7 @@ class ClassValue(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBase
|
||||
continue # These are not relevant for this search.
|
||||
|
||||
from jedi.inference.gradual.annotation import find_unknown_type_vars
|
||||
for type_var in find_unknown_type_vars(self.parent_value, node):
|
||||
for type_var in find_unknown_type_vars(self.parent_context, node):
|
||||
if type_var not in found:
|
||||
# The order matters and it's therefore a list.
|
||||
found.append(type_var)
|
||||
@@ -262,7 +262,7 @@ class ClassValue(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBase
|
||||
arglist = self.tree_node.get_super_arglist()
|
||||
if arglist:
|
||||
from jedi.inference import arguments
|
||||
return arguments.TreeArguments(self.infer_state, self.parent_value, arglist)
|
||||
return arguments.TreeArguments(self.infer_state, self.parent_context, arglist)
|
||||
return None
|
||||
|
||||
@infer_state_method_cache(default=())
|
||||
@@ -274,7 +274,7 @@ class ClassValue(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBase
|
||||
return lst
|
||||
|
||||
if self.py__name__() == 'object' \
|
||||
and self.parent_value == self.infer_state.builtins_module:
|
||||
and self.parent_context == self.infer_state.builtins_module:
|
||||
return []
|
||||
return [LazyKnownValues(
|
||||
self.infer_state.builtins_module.py__getattribute__('object')
|
||||
|
||||
@@ -20,20 +20,20 @@ class _ModuleAttributeName(AbstractNameDefinition):
|
||||
api_type = u'instance'
|
||||
|
||||
def __init__(self, parent_module, string_name, string_value=None):
|
||||
self.parent_value = parent_module
|
||||
self.parent_context = parent_module
|
||||
self.string_name = string_name
|
||||
self._string_value = string_value
|
||||
|
||||
def infer(self):
|
||||
if self._string_value is not None:
|
||||
s = self._string_value
|
||||
if self.parent_value.infer_state.environment.version_info.major == 2 \
|
||||
if self.parent_context.infer_state.environment.version_info.major == 2 \
|
||||
and not isinstance(s, bytes):
|
||||
s = s.encode('utf-8')
|
||||
return ValueSet([
|
||||
create_simple_object(self.parent_value.infer_state, s)
|
||||
create_simple_object(self.parent_context.infer_state, s)
|
||||
])
|
||||
return compiled.get_string_value_set(self.parent_value.infer_state)
|
||||
return compiled.get_string_value_set(self.parent_context.infer_state)
|
||||
|
||||
|
||||
class ModuleName(ValueNameMixin, AbstractNameDefinition):
|
||||
@@ -189,12 +189,12 @@ class ModuleMixin(SubModuleDictMixin):
|
||||
|
||||
class ModuleValue(ModuleMixin, TreeValue):
|
||||
api_type = u'module'
|
||||
parent_value = None
|
||||
parent_context = None
|
||||
|
||||
def __init__(self, infer_state, module_node, file_io, string_names, code_lines, is_package=False):
|
||||
super(ModuleValue, self).__init__(
|
||||
infer_state,
|
||||
parent_value=None,
|
||||
parent_context=None,
|
||||
tree_node=module_node
|
||||
)
|
||||
self.file_io = file_io
|
||||
|
||||
@@ -23,10 +23,10 @@ class ImplicitNamespaceValue(Value, SubModuleDictMixin):
|
||||
# folder foobar it will be available as an object:
|
||||
# <module 'foobar' (namespace)>.
|
||||
api_type = u'module'
|
||||
parent_value = None
|
||||
parent_context = None
|
||||
|
||||
def __init__(self, infer_state, fullname, paths):
|
||||
super(ImplicitNamespaceValue, self).__init__(infer_state, parent_value=None)
|
||||
super(ImplicitNamespaceValue, self).__init__(infer_state, parent_context=None)
|
||||
self.infer_state = infer_state
|
||||
self._fullname = fullname
|
||||
self._paths = paths
|
||||
|
||||
@@ -114,10 +114,10 @@ def execute(callback):
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
if value.parent_value == value.infer_state.builtins_module:
|
||||
if value.parent_context == value.infer_state.builtins_module:
|
||||
module_name = 'builtins'
|
||||
elif value.parent_value is not None and value.parent_value.is_module():
|
||||
module_name = value.parent_value.py__name__()
|
||||
elif value.parent_context is not None and value.parent_context.is_module():
|
||||
module_name = value.parent_context.py__name__()
|
||||
else:
|
||||
return call()
|
||||
|
||||
@@ -472,14 +472,14 @@ def collections_namedtuple(obj, arguments, callback):
|
||||
# Parse source code
|
||||
module = infer_state.grammar.parse(code)
|
||||
generated_class = next(module.iter_classdefs())
|
||||
parent_value = ModuleValue(
|
||||
parent_context = ModuleValue(
|
||||
infer_state, module,
|
||||
file_io=None,
|
||||
string_names=None,
|
||||
code_lines=parso.split_lines(code, keepends=True),
|
||||
)
|
||||
|
||||
return ValueSet([ClassValue(infer_state, parent_value, generated_class)])
|
||||
return ValueSet([ClassValue(infer_state, parent_context, generated_class)])
|
||||
|
||||
|
||||
class PartialObject(object):
|
||||
@@ -597,7 +597,7 @@ class DataclassWrapper(ValueWrapper, ClassMixin):
|
||||
else:
|
||||
default = annassign.children[3]
|
||||
param_names.append(DataclassParamName(
|
||||
parent_value=cls.parent_value,
|
||||
parent_context=cls.parent_context,
|
||||
tree_name=name.tree_name,
|
||||
annotation_node=annassign.children[1],
|
||||
default_node=default,
|
||||
@@ -615,8 +615,8 @@ class DataclassSignature(AbstractSignature):
|
||||
|
||||
|
||||
class DataclassParamName(BaseTreeParamName):
|
||||
def __init__(self, parent_value, tree_name, annotation_node, default_node):
|
||||
super(DataclassParamName, self).__init__(parent_value, tree_name)
|
||||
def __init__(self, parent_context, tree_name, annotation_node, default_node):
|
||||
super(DataclassParamName, self).__init__(parent_context, tree_name)
|
||||
self.annotation_node = annotation_node
|
||||
self.default_node = default_node
|
||||
|
||||
@@ -627,7 +627,7 @@ class DataclassParamName(BaseTreeParamName):
|
||||
if self.annotation_node is None:
|
||||
return NO_VALUES
|
||||
else:
|
||||
return self.parent_value.infer_node(self.annotation_node)
|
||||
return self.parent_context.infer_node(self.annotation_node)
|
||||
|
||||
|
||||
class ItemGetterCallable(ValueWrapper):
|
||||
|
||||
@@ -122,7 +122,7 @@ def _return_int():
|
||||
('ret_int', '_return_int', 'test.test_inference.test_compiled'),
|
||||
]
|
||||
)
|
||||
def test_parent_value(same_process_infer_state, attribute, expected_name, expected_parent):
|
||||
def test_parent_context(same_process_infer_state, attribute, expected_name, expected_parent):
|
||||
import decimal
|
||||
|
||||
class C:
|
||||
@@ -140,11 +140,11 @@ def test_parent_value(same_process_infer_state, attribute, expected_name, expect
|
||||
)
|
||||
x, = o.py__getattribute__(attribute)
|
||||
assert x.py__name__() == expected_name
|
||||
module_name = x.parent_value.py__name__()
|
||||
module_name = x.parent_context.py__name__()
|
||||
if module_name == '__builtin__':
|
||||
module_name = 'builtins' # Python 2
|
||||
assert module_name == expected_parent
|
||||
assert x.parent_value.parent_value is None
|
||||
assert x.parent_context.parent_context is None
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
|
||||
|
||||
@@ -156,8 +156,8 @@ def test_not_importable_file(Script):
|
||||
def test_import_unique(Script):
|
||||
src = "import os; os.path"
|
||||
defs = Script(src, path='example.py').goto_definitions()
|
||||
parent_values = [d._name._value for d in defs]
|
||||
assert len(parent_values) == len(set(parent_values))
|
||||
parent_contexts = [d._name._value for d in defs]
|
||||
assert len(parent_contexts) == len(set(parent_contexts))
|
||||
|
||||
|
||||
def test_cache_works_with_sys_path_param(Script, tmpdir):
|
||||
|
||||
@@ -15,7 +15,7 @@ def test_base_auto_import_modules(auto_import_json, Script):
|
||||
loads, = Script('import json; json.loads').goto_definitions()
|
||||
assert isinstance(loads._name, ValueName)
|
||||
value, = loads._name.infer()
|
||||
assert isinstance(value.parent_value, StubModuleValue)
|
||||
assert isinstance(value.parent_context, StubModuleValue)
|
||||
|
||||
|
||||
def test_auto_import_modules_imports(auto_import_json, Script):
|
||||
|
||||
Reference in New Issue
Block a user