diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index e8a9a016..2f8be3a9 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -82,17 +82,20 @@ class CompiledObject(Base): return CompiledObject(c, self.parent) return self - @underscore_memoization def get_defined_names(self): + if inspect.ismodule(self.obj): + return self.instance_names() + else: + return type_names + self.instance_names() + + @underscore_memoization + def instance_names(self): names = [] cls = self._cls() for name in dir(cls.obj): names.append(CompiledName(cls, name)) return names - def instance_names(self): - return self.get_defined_names() - def get_subscope_by_name(self, name): if name in dir(self._cls().obj): return CompiledName(self._cls(), name).parent @@ -355,10 +358,6 @@ def _a_generator(foo): yield 42 yield foo -builtin = Builtin(_builtins) -magic_function_class = CompiledObject(type(load_module), parent=builtin) -generator_obj = CompiledObject(_a_generator(1.0)) - def _create_from_name(module, parent, name): faked = fake.get_faked(module.obj, parent.obj, name) @@ -377,6 +376,13 @@ def _create_from_name(module, parent, name): return CompiledObject(obj, parent) +builtin = Builtin(_builtins) +magic_function_class = CompiledObject(type(load_module), parent=builtin) +generator_obj = CompiledObject(_a_generator(1.0)) +type_names = [] # Need this, because it's return in get_defined_names. +type_names = builtin.get_by_name('type').get_defined_names() + + def compiled_objects_cache(func): def wrapper(evaluator, obj, parent=builtin, module=None): # Do a very cheap form of caching here. diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 47252e29..288e18ee 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -303,12 +303,9 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)): # TODO mro! for cls in self.get_super_classes(): # Get the inherited names. - if isinstance(cls, compiled.CompiledObject): - super_result += cls.get_defined_names() - else: - for i in cls.instance_names(): - if not in_iterable(i, result): - super_result.append(i) + for i in cls.instance_names(): + if not in_iterable(i, result): + super_result.append(i) result += super_result return result diff --git a/test/completion/stdlib.py b/test/completion/stdlib.py index 332a9976..523497df 100644 --- a/test/completion/stdlib.py +++ b/test/completion/stdlib.py @@ -31,6 +31,10 @@ next(open('')) #? int() {'a':2}.setdefault('a', 3) +# Compiled classes should have the meta class attributes. +#? ['__itemsize__'] +tuple.__itemsize__ + # ----------------- # re # -----------------