mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
CompiledObject.type resembles now the Node.type values.
This commit is contained in:
@@ -149,7 +149,7 @@ class BaseDefinition(object):
|
|||||||
stripped = stripped.var
|
stripped = stripped.var
|
||||||
|
|
||||||
if isinstance(stripped, compiled.CompiledObject):
|
if isinstance(stripped, compiled.CompiledObject):
|
||||||
return stripped.type()
|
return stripped.api_type()
|
||||||
elif isinstance(stripped, iterable.Array):
|
elif isinstance(stripped, iterable.Array):
|
||||||
return 'instance'
|
return 'instance'
|
||||||
elif isinstance(stripped, pr.Import):
|
elif isinstance(stripped, pr.Import):
|
||||||
@@ -530,7 +530,7 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
|||||||
d = d.var
|
d = d.var
|
||||||
|
|
||||||
if isinstance(d, compiled.CompiledObject):
|
if isinstance(d, compiled.CompiledObject):
|
||||||
typ = d.type()
|
typ = d.api_type()
|
||||||
if typ == 'instance':
|
if typ == 'instance':
|
||||||
typ = 'class' # The description should be similar to Py objects.
|
typ = 'class' # The description should be similar to Py objects.
|
||||||
d = typ + ' ' + d.name.get_code()
|
d = typ + ' ' + d.name.get_code()
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class CompiledObject(Base):
|
|||||||
|
|
||||||
return _parse_function_doc(self.doc)
|
return _parse_function_doc(self.doc)
|
||||||
|
|
||||||
def type(self):
|
def api_type(self):
|
||||||
if fake.is_class_instance(self.obj):
|
if fake.is_class_instance(self.obj):
|
||||||
return 'instance'
|
return 'instance'
|
||||||
|
|
||||||
@@ -123,6 +123,18 @@ class CompiledObject(Base):
|
|||||||
or inspect.ismethoddescriptor(cls):
|
or inspect.ismethoddescriptor(cls):
|
||||||
return 'function'
|
return 'function'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
"""Imitate the tree.Node.type values."""
|
||||||
|
cls = self._cls().obj
|
||||||
|
if inspect.isclass(cls):
|
||||||
|
return 'classdef'
|
||||||
|
elif inspect.ismodule(cls):
|
||||||
|
return 'file_input'
|
||||||
|
elif inspect.isbuiltin(cls) or inspect.ismethod(cls) \
|
||||||
|
or inspect.ismethoddescriptor(cls):
|
||||||
|
return 'funcdef'
|
||||||
|
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def _cls(self):
|
def _cls(self):
|
||||||
# Ensures that a CompiledObject is returned that is not an instance (like list)
|
# Ensures that a CompiledObject is returned that is not an instance (like list)
|
||||||
@@ -195,7 +207,7 @@ class CompiledObject(Base):
|
|||||||
return FakeName(self._cls().obj.__name__, self)
|
return FakeName(self._cls().obj.__name__, self)
|
||||||
|
|
||||||
def _execute_function(self, evaluator, params):
|
def _execute_function(self, evaluator, params):
|
||||||
if self.type() != 'function':
|
if self.type != 'funcdef':
|
||||||
return
|
return
|
||||||
|
|
||||||
for name in self._parse_function_doc()[1].split():
|
for name in self._parse_function_doc()[1].split():
|
||||||
|
|||||||
@@ -467,8 +467,7 @@ def global_names_dict_generator(evaluator, scope, position):
|
|||||||
"""
|
"""
|
||||||
in_func = False
|
in_func = False
|
||||||
while scope is not None:
|
while scope is not None:
|
||||||
if not((scope.type == 'classdef' or isinstance(scope,
|
if not (scope.type == 'classdef' and in_func):
|
||||||
compiled.CompiledObject) and scope.type() == 'class') and in_func):
|
|
||||||
# Names in methods cannot be resolved within the class.
|
# Names in methods cannot be resolved within the class.
|
||||||
|
|
||||||
for names_dict in scope.names_dicts(True):
|
for names_dict in scope.names_dicts(True):
|
||||||
|
|||||||
@@ -432,8 +432,7 @@ class _Importer(object):
|
|||||||
|
|
||||||
for scope in self.follow(evaluator):
|
for scope in self.follow(evaluator):
|
||||||
# Non-modules are not completable.
|
# Non-modules are not completable.
|
||||||
if not isinstance(scope, er.ModuleWrapper) and not (isinstance(scope,
|
if not scope.type == 'file_input': # not a module
|
||||||
compiled.CompiledObject) and scope.type() == 'module'):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# namespace packages
|
# namespace packages
|
||||||
|
|||||||
@@ -169,4 +169,4 @@ def test_loading_unicode_files_with_bad_global_charset(monkeypatch, tmpdir):
|
|||||||
f.write(data)
|
f.write(data)
|
||||||
s = Script("from test1 import foo\nfoo.",
|
s = Script("from test1 import foo\nfoo.",
|
||||||
line=2, column=4, path=filename2)
|
line=2, column=4, path=filename2)
|
||||||
s.complete()
|
s.completions()
|
||||||
|
|||||||
Reference in New Issue
Block a user