Remove type(self).__name__ occurences, because python 2 will always output 'instance'.

This commit is contained in:
Dave Halter
2016-11-08 19:18:03 +01:00
parent 4a8fd73601
commit 20380e80b0
6 changed files with 31 additions and 32 deletions

View File

@@ -99,7 +99,7 @@ class CompiledObject(Context):
return params
def __repr__(self):
return '<%s: %s>' % (type(self).__name__, repr(self.obj))
return '<%s: %s>' % (self.__class__.__name__, repr(self.obj))
@underscore_memoization
def _parse_function_doc(self):
@@ -277,7 +277,7 @@ class CompiledName(AbstractNameDefinition):
name = self.parent_context.name # __name__ is not defined all the time
except AttributeError:
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
def infer(self):

View File

@@ -33,6 +33,7 @@ from jedi.evaluate import analysis
from jedi.evaluate import flow_analysis
from jedi.evaluate import param
from jedi.evaluate import helpers
from jedi.evaluate.instance import AbstractInstanceContext
from jedi.evaluate.cache import memoize_default
from jedi.evaluate.filters import get_global_filters
@@ -274,22 +275,19 @@ class NameFinder(object):
def _check_getattr(self, inst):
"""Checks for both __getattr__ and __getattribute__ methods"""
result = set()
# str is important, because it shouldn't be `Name`!
name = compiled.create(self._evaluator, str(self.name_str))
with common.ignored(KeyError):
result = inst.execute_subscope_by_name('__getattr__', name)
if not result:
# This is a little bit special. `__getattribute__` is in Python
# executed before `__getattr__`. But: I know no use case, where
# this could be practical and where jedi would return wrong types.
# If you ever find something, let me know!
# We are inversing this, because a hand-crafted `__getattribute__`
# could still call another hand-crafted `__getattr__`, but not the
# other way around.
with common.ignored(KeyError):
result = inst.execute_subscope_by_name('__getattribute__', name)
return result
# This is a little bit special. `__getattribute__` is in Python
# executed before `__getattr__`. But: I know no use case, where
# this could be practical and where Jedi would return wrong types.
# If you ever find something, let me know!
# We are inversing this, because a hand-crafted `__getattribute__`
# could still call another hand-crafted `__getattr__`, but not the
# other way around.
names = (inst.get_function_slot_names('__getattr__') or
inst.get_function_slot_names('__getattribute__'))
return inst.execute_function_slots(names, name)
def _names_to_types(self, names, attribute_lookup):
types = set()
@@ -315,7 +313,8 @@ class NameFinder(object):
types |= set(self._resolve_descriptors(name, new_types))
else:
types |= set(new_types)
if not names and isinstance(self.context, er.Instance):
if not names and isinstance(self.context, AbstractInstanceContext):
# handling __getattr__ / __getattribute__
return self._check_getattr(self.context)

View File

@@ -44,7 +44,7 @@ class AbstractInstanceContext(Context):
@property
def py__call__(self):
names = self._get_function_slot_names('__call__')
names = self.get_function_slot_names('__call__')
if not names:
# Means the Instance is not callable.
raise AttributeError
@@ -61,7 +61,7 @@ class AbstractInstanceContext(Context):
# Signalize that we don't know about the bool type.
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
# looking up `__call__`. This is something that has to do with Python's
# internal slot system (note: not __slots__, but C slots).
@@ -73,7 +73,7 @@ class AbstractInstanceContext(Context):
def execute_function_slots(self, names, *evaluated_args):
return unite(
self.evaluator.execute_evaluated(method, *evaluated_args)
self.execute_evaluated(method, *evaluated_args)
for name in names
for method in name.infer()
)
@@ -82,7 +82,7 @@ class AbstractInstanceContext(Context):
""" Throws a KeyError if there's no method. """
# Arguments in __get__ descriptors are obj, class.
# `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 isinstance(obj, AbstractInstanceContext):
return self.execute_function_slots(names, obj, obj.class_context)
@@ -109,7 +109,7 @@ class AbstractInstanceContext(Context):
def py__getitem__(self, index):
try:
names = self._get_function_slot_names('__getitem__')
names = self.get_function_slot_names('__getitem__')
except KeyError:
debug.warning('No __getitem__, cannot access the array.')
return set()
@@ -142,7 +142,7 @@ class AbstractInstanceContext(Context):
pass
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)

View File

@@ -440,7 +440,7 @@ class ArrayLiteralContext(ArrayMixin, AbstractSequence):
yield key.obj, context.LazyTreeContext(self._defining_context, value)
def __repr__(self):
return "<%s of %s>" % (type(self).__name__, self.atom)
return "<%s of %s>" % (self.__class__.__name__, self.atom)
class _FakeArray(ArrayLiteralContext):

View File

@@ -169,7 +169,7 @@ class ValuesArguments(AbstractArguments):
return None
def __repr__(self):
return '<%s: %s>' % (type(self).__name__, self._values_list)
return '<%s: %s>' % (self.__class__.__name__, self._values_list)
class ExecutedParam(object):
@@ -189,7 +189,7 @@ class ExecutedParam(object):
return self._original_param.position_nr
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):

View File

@@ -255,7 +255,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
return ContextName(self, self._class_context.name.string_name)
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)
@@ -388,7 +388,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, tree.Base)):
return FunctionContext.py__call__(self, params)
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):
@@ -507,7 +507,7 @@ class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrapper))
raise KeyError("Couldn't find subscope.")
def __repr__(self):
return "<%s of %s>" % (type(self).__name__, self.classdef)
return "<%s of %s>" % (self.__type__.__name__, self.classdef)
@property
def name(self):
@@ -568,7 +568,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrappe
return compiled.get_special_object(self.evaluator, name)
def __repr__(self):
return "<%s of %s>" % (type(self).__name__, self.base_func)
return "<%s of %s>" % (self.__type__.__name__, self.base_func)
@property
def name(self):
@@ -718,7 +718,7 @@ class FunctionExecutionContext(Executed):
return param.get_params(self.evaluator, self.parent_context, self.funcdef, self.var_args)
def __repr__(self):
return "<%s of %s>" % (type(self).__name__, self.funcdef)
return "<%s of %s>" % (self.__class__.__name__, self.funcdef)
class AnonymousFunctionExecution(FunctionExecutionContext):
@@ -920,4 +920,4 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrapper)
return compiled.get_special_object(self.evaluator, 'MODULE_CLASS')
def __repr__(self):
return "<%s: %s>" % (type(self).__name__, self.module_node)
return "<%s: %s>" % (self.__class__.__name__, self.module_node)