mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
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:
@@ -82,17 +82,20 @@ class CompiledObject(Base):
|
|||||||
return CompiledObject(c, self.parent)
|
return CompiledObject(c, self.parent)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@underscore_memoization
|
|
||||||
def get_defined_names(self):
|
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 = []
|
names = []
|
||||||
cls = self._cls()
|
cls = self._cls()
|
||||||
for name in dir(cls.obj):
|
for name in dir(cls.obj):
|
||||||
names.append(CompiledName(cls, name))
|
names.append(CompiledName(cls, name))
|
||||||
return names
|
return names
|
||||||
|
|
||||||
def instance_names(self):
|
|
||||||
return self.get_defined_names()
|
|
||||||
|
|
||||||
def get_subscope_by_name(self, name):
|
def get_subscope_by_name(self, name):
|
||||||
if name in dir(self._cls().obj):
|
if name in dir(self._cls().obj):
|
||||||
return CompiledName(self._cls(), name).parent
|
return CompiledName(self._cls(), name).parent
|
||||||
@@ -355,10 +358,6 @@ def _a_generator(foo):
|
|||||||
yield 42
|
yield 42
|
||||||
yield foo
|
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):
|
def _create_from_name(module, parent, name):
|
||||||
faked = fake.get_faked(module.obj, parent.obj, 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)
|
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 compiled_objects_cache(func):
|
||||||
def wrapper(evaluator, obj, parent=builtin, module=None):
|
def wrapper(evaluator, obj, parent=builtin, module=None):
|
||||||
# Do a very cheap form of caching here.
|
# Do a very cheap form of caching here.
|
||||||
|
|||||||
@@ -303,9 +303,6 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
|
|||||||
# TODO mro!
|
# TODO mro!
|
||||||
for cls in self.get_super_classes():
|
for cls in self.get_super_classes():
|
||||||
# Get the inherited names.
|
# Get the inherited names.
|
||||||
if isinstance(cls, compiled.CompiledObject):
|
|
||||||
super_result += cls.get_defined_names()
|
|
||||||
else:
|
|
||||||
for i in cls.instance_names():
|
for i in cls.instance_names():
|
||||||
if not in_iterable(i, result):
|
if not in_iterable(i, result):
|
||||||
super_result.append(i)
|
super_result.append(i)
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ next(open(''))
|
|||||||
#? int()
|
#? int()
|
||||||
{'a':2}.setdefault('a', 3)
|
{'a':2}.setdefault('a', 3)
|
||||||
|
|
||||||
|
# Compiled classes should have the meta class attributes.
|
||||||
|
#? ['__itemsize__']
|
||||||
|
tuple.__itemsize__
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# re
|
# re
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user