1
0
forked from VimPlug/jedi

Get closer to fixing a lot of issues with the completion for repl.

This commit is contained in:
Dave Halter
2016-05-15 14:26:10 +02:00
parent beeffd2dcd
commit cc331d62e0
6 changed files with 97 additions and 59 deletions

View File

@@ -113,7 +113,7 @@ class CompiledObject(Base):
elif inspect.ismodule(cls):
return 'module'
elif inspect.isbuiltin(cls) or inspect.ismethod(cls) \
or inspect.ismethoddescriptor(cls):
or inspect.ismethoddescriptor(cls) or inspect.isfunction(cls):
return 'function'
@property

View File

@@ -6,6 +6,7 @@ mixing in Python code, the autocompletion should work much better for builtins.
import os
import inspect
import types
from jedi._compatibility import is_py3, builtins, unicode
from jedi.parser import ParserWithRecovery, load_grammar
@@ -15,6 +16,28 @@ from jedi.evaluate.helpers import FakeName
modules = {}
MethodDescriptorType = type(str.replace)
# These are not considered classes and access is granted even though they have
# a __class__ attribute.
NOT_CLASS_TYPES = (
types.BuiltinFunctionType,
types.CodeType,
types.DynamicClassAttribute,
types.FrameType,
types.FunctionType,
types.GeneratorType,
types.GetSetDescriptorType,
types.LambdaType,
types.MappingProxyType,
types.MemberDescriptorType,
types.MethodType,
types.ModuleType,
types.SimpleNamespace,
types.TracebackType,
MethodDescriptorType
)
def _load_faked_module(module):
module_name = module.__name__
if module_name == '__builtin__' and not is_py3:
@@ -134,7 +157,9 @@ def get_faked(module, obj, name=None):
def is_class_instance(obj):
"""Like inspect.* methods."""
return not (inspect.isclass(obj) or inspect.ismodule(obj)
or inspect.isbuiltin(obj) or inspect.ismethod(obj)
or inspect.ismethoddescriptor(obj) or inspect.iscode(obj)
or inspect.isgenerator(obj))
try:
cls = obj.__class__
except AttributeError:
return False
else:
return cls != type and not issubclass(cls, NOT_CLASS_TYPES)