mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-19 03:55:57 +08:00
Remove type(self).__name__ occurences, because python 2 will always output 'instance'.
This commit is contained in:
@@ -99,7 +99,7 @@ class CompiledObject(Context):
|
|||||||
return params
|
return params
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, repr(self.obj))
|
return '<%s: %s>' % (self.__class__.__name__, repr(self.obj))
|
||||||
|
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def _parse_function_doc(self):
|
def _parse_function_doc(self):
|
||||||
@@ -277,7 +277,7 @@ class CompiledName(AbstractNameDefinition):
|
|||||||
name = self.parent_context.name # __name__ is not defined all the time
|
name = self.parent_context.name # __name__ is not defined all the time
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
name = None
|
name = None
|
||||||
return '<%s: (%s).%s>' % (type(self).__name__, name, self.string_name)
|
return '<%s: (%s).%s>' % (self.__class__.__name__, name, self.string_name)
|
||||||
|
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def infer(self):
|
def infer(self):
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ from jedi.evaluate import analysis
|
|||||||
from jedi.evaluate import flow_analysis
|
from jedi.evaluate import flow_analysis
|
||||||
from jedi.evaluate import param
|
from jedi.evaluate import param
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
|
from jedi.evaluate.instance import AbstractInstanceContext
|
||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default
|
||||||
from jedi.evaluate.filters import get_global_filters
|
from jedi.evaluate.filters import get_global_filters
|
||||||
|
|
||||||
@@ -274,22 +275,19 @@ class NameFinder(object):
|
|||||||
|
|
||||||
def _check_getattr(self, inst):
|
def _check_getattr(self, inst):
|
||||||
"""Checks for both __getattr__ and __getattribute__ methods"""
|
"""Checks for both __getattr__ and __getattribute__ methods"""
|
||||||
result = set()
|
|
||||||
# str is important, because it shouldn't be `Name`!
|
# str is important, because it shouldn't be `Name`!
|
||||||
name = compiled.create(self._evaluator, str(self.name_str))
|
name = compiled.create(self._evaluator, str(self.name_str))
|
||||||
with common.ignored(KeyError):
|
|
||||||
result = inst.execute_subscope_by_name('__getattr__', name)
|
# This is a little bit special. `__getattribute__` is in Python
|
||||||
if not result:
|
# executed before `__getattr__`. But: I know no use case, where
|
||||||
# This is a little bit special. `__getattribute__` is in Python
|
# this could be practical and where Jedi would return wrong types.
|
||||||
# executed before `__getattr__`. But: I know no use case, where
|
# If you ever find something, let me know!
|
||||||
# this could be practical and where jedi would return wrong types.
|
# We are inversing this, because a hand-crafted `__getattribute__`
|
||||||
# If you ever find something, let me know!
|
# could still call another hand-crafted `__getattr__`, but not the
|
||||||
# We are inversing this, because a hand-crafted `__getattribute__`
|
# other way around.
|
||||||
# could still call another hand-crafted `__getattr__`, but not the
|
names = (inst.get_function_slot_names('__getattr__') or
|
||||||
# other way around.
|
inst.get_function_slot_names('__getattribute__'))
|
||||||
with common.ignored(KeyError):
|
return inst.execute_function_slots(names, name)
|
||||||
result = inst.execute_subscope_by_name('__getattribute__', name)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _names_to_types(self, names, attribute_lookup):
|
def _names_to_types(self, names, attribute_lookup):
|
||||||
types = set()
|
types = set()
|
||||||
@@ -315,7 +313,8 @@ class NameFinder(object):
|
|||||||
types |= set(self._resolve_descriptors(name, new_types))
|
types |= set(self._resolve_descriptors(name, new_types))
|
||||||
else:
|
else:
|
||||||
types |= set(new_types)
|
types |= set(new_types)
|
||||||
if not names and isinstance(self.context, er.Instance):
|
|
||||||
|
if not names and isinstance(self.context, AbstractInstanceContext):
|
||||||
# handling __getattr__ / __getattribute__
|
# handling __getattr__ / __getattribute__
|
||||||
return self._check_getattr(self.context)
|
return self._check_getattr(self.context)
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class AbstractInstanceContext(Context):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def py__call__(self):
|
def py__call__(self):
|
||||||
names = self._get_function_slot_names('__call__')
|
names = self.get_function_slot_names('__call__')
|
||||||
if not names:
|
if not names:
|
||||||
# Means the Instance is not callable.
|
# Means the Instance is not callable.
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
@@ -61,7 +61,7 @@ class AbstractInstanceContext(Context):
|
|||||||
# Signalize that we don't know about the bool type.
|
# Signalize that we don't know about the bool type.
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _get_function_slot_names(self, name):
|
def get_function_slot_names(self, name):
|
||||||
# Python classes don't look at the dictionary of the instance when
|
# Python classes don't look at the dictionary of the instance when
|
||||||
# looking up `__call__`. This is something that has to do with Python's
|
# looking up `__call__`. This is something that has to do with Python's
|
||||||
# internal slot system (note: not __slots__, but C slots).
|
# internal slot system (note: not __slots__, but C slots).
|
||||||
@@ -73,7 +73,7 @@ class AbstractInstanceContext(Context):
|
|||||||
|
|
||||||
def execute_function_slots(self, names, *evaluated_args):
|
def execute_function_slots(self, names, *evaluated_args):
|
||||||
return unite(
|
return unite(
|
||||||
self.evaluator.execute_evaluated(method, *evaluated_args)
|
self.execute_evaluated(method, *evaluated_args)
|
||||||
for name in names
|
for name in names
|
||||||
for method in name.infer()
|
for method in name.infer()
|
||||||
)
|
)
|
||||||
@@ -82,7 +82,7 @@ class AbstractInstanceContext(Context):
|
|||||||
""" Throws a KeyError if there's no method. """
|
""" Throws a KeyError if there's no method. """
|
||||||
# Arguments in __get__ descriptors are obj, class.
|
# Arguments in __get__ descriptors are obj, class.
|
||||||
# `method` is the new parent of the array, don't know if that's good.
|
# `method` is the new parent of the array, don't know if that's good.
|
||||||
names = self._get_function_slot_names('__get__')
|
names = self.get_function_slot_names('__get__')
|
||||||
if names:
|
if names:
|
||||||
if isinstance(obj, AbstractInstanceContext):
|
if isinstance(obj, AbstractInstanceContext):
|
||||||
return self.execute_function_slots(names, obj, obj.class_context)
|
return self.execute_function_slots(names, obj, obj.class_context)
|
||||||
@@ -109,7 +109,7 @@ class AbstractInstanceContext(Context):
|
|||||||
|
|
||||||
def py__getitem__(self, index):
|
def py__getitem__(self, index):
|
||||||
try:
|
try:
|
||||||
names = self._get_function_slot_names('__getitem__')
|
names = self.get_function_slot_names('__getitem__')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
debug.warning('No __getitem__, cannot access the array.')
|
debug.warning('No __getitem__, cannot access the array.')
|
||||||
return set()
|
return set()
|
||||||
@@ -142,7 +142,7 @@ class AbstractInstanceContext(Context):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s(%s)>" % (type(self).__name__, self.class_context,
|
return "<%s of %s(%s)>" % (self.__class__.__name__, self.class_context,
|
||||||
self.var_args)
|
self.var_args)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ class ArrayLiteralContext(ArrayMixin, AbstractSequence):
|
|||||||
yield key.obj, context.LazyTreeContext(self._defining_context, value)
|
yield key.obj, context.LazyTreeContext(self._defining_context, value)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self.atom)
|
return "<%s of %s>" % (self.__class__.__name__, self.atom)
|
||||||
|
|
||||||
|
|
||||||
class _FakeArray(ArrayLiteralContext):
|
class _FakeArray(ArrayLiteralContext):
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class ValuesArguments(AbstractArguments):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self._values_list)
|
return '<%s: %s>' % (self.__class__.__name__, self._values_list)
|
||||||
|
|
||||||
|
|
||||||
class ExecutedParam(object):
|
class ExecutedParam(object):
|
||||||
@@ -189,7 +189,7 @@ class ExecutedParam(object):
|
|||||||
return self._original_param.position_nr
|
return self._original_param.position_nr
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self.string_name)
|
return '<%s: %s>' % (self.__class__.__name__, self.string_name)
|
||||||
|
|
||||||
|
|
||||||
def _get_calling_var_args(evaluator, var_args):
|
def _get_calling_var_args(evaluator, var_args):
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
return ContextName(self, self._class_context.name.string_name)
|
return ContextName(self, self._class_context.name.string_name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s(%s)>" % (type(self).__name__, self._class_context,
|
return "<%s of %s(%s)>" % (self.__type__.__name__, self._class_context,
|
||||||
self.var_args)
|
self.var_args)
|
||||||
|
|
||||||
|
|
||||||
@@ -388,7 +388,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, tree.Base)):
|
|||||||
return FunctionContext.py__call__(self, params)
|
return FunctionContext.py__call__(self, params)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self.var)
|
return "<%s of %s>" % (self.__type__.__name__, self.var)
|
||||||
|
|
||||||
|
|
||||||
class Wrapper(tree.Base):
|
class Wrapper(tree.Base):
|
||||||
@@ -507,7 +507,7 @@ class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrapper))
|
|||||||
raise KeyError("Couldn't find subscope.")
|
raise KeyError("Couldn't find subscope.")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self.classdef)
|
return "<%s of %s>" % (self.__type__.__name__, self.classdef)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@@ -568,7 +568,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrappe
|
|||||||
return compiled.get_special_object(self.evaluator, name)
|
return compiled.get_special_object(self.evaluator, name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self.base_func)
|
return "<%s of %s>" % (self.__type__.__name__, self.base_func)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@@ -718,7 +718,7 @@ class FunctionExecutionContext(Executed):
|
|||||||
return param.get_params(self.evaluator, self.parent_context, self.funcdef, self.var_args)
|
return param.get_params(self.evaluator, self.parent_context, self.funcdef, self.var_args)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self.funcdef)
|
return "<%s of %s>" % (self.__class__.__name__, self.funcdef)
|
||||||
|
|
||||||
|
|
||||||
class AnonymousFunctionExecution(FunctionExecutionContext):
|
class AnonymousFunctionExecution(FunctionExecutionContext):
|
||||||
@@ -920,4 +920,4 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrapper)
|
|||||||
return compiled.get_special_object(self.evaluator, 'MODULE_CLASS')
|
return compiled.get_special_object(self.evaluator, 'MODULE_CLASS')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s>" % (type(self).__name__, self.module_node)
|
return "<%s: %s>" % (self.__class__.__name__, self.module_node)
|
||||||
|
|||||||
Reference in New Issue
Block a user