mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-20 04:21:13 +08:00
fixing parents in compiled
This commit is contained in:
@@ -26,12 +26,15 @@ class PyObject(Base):
|
|||||||
self.doc = inspect.getdoc(obj)
|
self.doc = inspect.getdoc(obj)
|
||||||
|
|
||||||
# comply with the parser
|
# comply with the parser
|
||||||
self.get_parent_until = lambda *args, **kwargs: parent or self
|
|
||||||
self.start_pos = 0, 0
|
self.start_pos = 0, 0
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self.obj)
|
return '<%s: %s>' % (type(self).__name__, self.obj)
|
||||||
|
|
||||||
|
def get_parent_until(self, *args, **kwargs):
|
||||||
|
# compiled modules only use functions and classes/methods (2 levels)
|
||||||
|
return getattr(self.parent, 'parent', self.parent) or self
|
||||||
|
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def _parse_function_doc(self):
|
def _parse_function_doc(self):
|
||||||
if self.doc is None:
|
if self.doc is None:
|
||||||
@@ -99,7 +102,8 @@ class PyName(object):
|
|||||||
def parent(self):
|
def parent(self):
|
||||||
try:
|
try:
|
||||||
# this has a builtin_function_or_method
|
# this has a builtin_function_or_method
|
||||||
return create(getattr(self._obj.obj, self._name), self._obj)
|
return create(getattr(self._obj.obj, self._name), self._obj,
|
||||||
|
module=self._obj.get_parent_until())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# happens e.g. in properties of
|
# happens e.g. in properties of
|
||||||
# PyQt4.QtGui.QStyleOptionComboBox.currentText
|
# PyQt4.QtGui.QStyleOptionComboBox.currentText
|
||||||
@@ -160,7 +164,6 @@ def _parse_function_doc(doc):
|
|||||||
TODO docstrings like utime(path, (atime, mtime)) and a(b [, b]) -> None
|
TODO docstrings like utime(path, (atime, mtime)) and a(b [, b]) -> None
|
||||||
TODO docstrings like 'tuple of integers'
|
TODO docstrings like 'tuple of integers'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# parse round parentheses: def func(a, (b,c))
|
# parse round parentheses: def func(a, (b,c))
|
||||||
try:
|
try:
|
||||||
count = 0
|
count = 0
|
||||||
@@ -218,8 +221,8 @@ magic_function_class = PyObject(type(load_module), parent=builtin)
|
|||||||
|
|
||||||
|
|
||||||
def create(obj, parent=builtin, instantiated=False, module=None):
|
def create(obj, parent=builtin, instantiated=False, module=None):
|
||||||
if module is None:
|
if not inspect.ismodule(obj):
|
||||||
if not inspect.ismodule(obj):
|
if module is None:
|
||||||
module = obj.__class__ if fake.is_class_instance(obj) else obj
|
module = obj.__class__ if fake.is_class_instance(obj) else obj
|
||||||
if not (inspect.isbuiltin(module) or inspect.isclass(module)):
|
if not (inspect.isbuiltin(module) or inspect.isclass(module)):
|
||||||
module = obj.__objclass__
|
module = obj.__objclass__
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ def test_simple():
|
|||||||
|
|
||||||
|
|
||||||
def test_fake_loading():
|
def test_fake_loading():
|
||||||
assert isinstance(compiled.create(reversed), Function)
|
assert isinstance(compiled.create(next), Function)
|
||||||
|
|||||||
Reference in New Issue
Block a user