From 20380e80b02daae4bc2ba52139c4b5f532e9b37d Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 8 Nov 2016 19:18:03 +0100 Subject: [PATCH] Remove type(self).__name__ occurences, because python 2 will always output 'instance'. --- jedi/evaluate/compiled/__init__.py | 4 ++-- jedi/evaluate/finder.py | 29 ++++++++++++++--------------- jedi/evaluate/instance.py | 12 ++++++------ jedi/evaluate/iterable.py | 2 +- jedi/evaluate/param.py | 4 ++-- jedi/evaluate/representation.py | 12 ++++++------ 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index afd81516..6b39e599 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -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): diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 7c886d76..94fc41de 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -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) diff --git a/jedi/evaluate/instance.py b/jedi/evaluate/instance.py index 2b84c859..4ea4a57e 100644 --- a/jedi/evaluate/instance.py +++ b/jedi/evaluate/instance.py @@ -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) diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 92b4eb7a..aa58887c 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -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): diff --git a/jedi/evaluate/param.py b/jedi/evaluate/param.py index 8c3a70bc..867c7282 100644 --- a/jedi/evaluate/param.py +++ b/jedi/evaluate/param.py @@ -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): diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index fdd61487..fc5bedf9 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -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)