types also add to completions, also for compiled objects. removed a few lines of code that complicated the process as well.

This commit is contained in:
Dave Halter
2014-06-28 12:09:43 +02:00
parent 7d73e571bb
commit 5b7c869323
3 changed files with 21 additions and 14 deletions

View File

@@ -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.

View File

@@ -303,9 +303,6 @@ 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)

View File

@@ -31,6 +31,10 @@ next(open(''))
#? int()
{'a':2}.setdefault('a', 3)
# Compiled classes should have the meta class attributes.
#? ['__itemsize__']
tuple.__itemsize__
# -----------------
# re
# -----------------