forked from VimPlug/jedi
Make params work with access
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import inspect
|
||||
import types
|
||||
import operator as op
|
||||
from collections import namedtuple
|
||||
|
||||
from jedi._compatibility import unicode, is_py3, is_py34, builtins
|
||||
from jedi._compatibility import unicode, is_py3, is_py34, builtins, py_version
|
||||
from jedi.evaluate.compiled.getattr_static import getattr_static
|
||||
|
||||
|
||||
@@ -72,6 +73,7 @@ _OPERATORS = {
|
||||
_OPERATORS.update(COMPARISON_OPERATORS)
|
||||
|
||||
|
||||
SignatureParam = namedtuple('SignatureParam', 'name default empty annotation')
|
||||
|
||||
|
||||
class DirectObjectAccess(object):
|
||||
@@ -142,6 +144,9 @@ class DirectObjectAccess(object):
|
||||
def is_class(self):
|
||||
return inspect.isclass(self._obj)
|
||||
|
||||
def ismethoddescriptor(self):
|
||||
return inspect.ismethoddescriptor(self._obj)
|
||||
|
||||
def dir(self):
|
||||
return dir(self._obj)
|
||||
|
||||
@@ -242,6 +247,36 @@ class DirectObjectAccess(object):
|
||||
def needs_type_completions(self):
|
||||
return inspect.isclass(self._obj) and self._obj != type
|
||||
|
||||
def get_signature_params(self):
|
||||
obj = self._obj
|
||||
if py_version < 33:
|
||||
raise ValueError("inspect.signature was introduced in 3.3")
|
||||
if py_version == 34:
|
||||
# In 3.4 inspect.signature are wrong for str and int. This has
|
||||
# been fixed in 3.5. The signature of object is returned,
|
||||
# because no signature was found for str. Here we imitate 3.5
|
||||
# logic and just ignore the signature if the magic methods
|
||||
# don't match object.
|
||||
# 3.3 doesn't even have the logic and returns nothing for str
|
||||
# and classes that inherit from object.
|
||||
user_def = inspect._signature_get_user_defined_method
|
||||
if (inspect.isclass(obj)
|
||||
and not user_def(type(obj), '__init__')
|
||||
and not user_def(type(obj), '__new__')
|
||||
and (obj.__init__ != object.__init__
|
||||
or obj.__new__ != object.__new__)):
|
||||
raise ValueError
|
||||
|
||||
signature = inspect.signature(obj)
|
||||
return [
|
||||
SignatureParam(
|
||||
name=p.name,
|
||||
default=p.default,
|
||||
empty=p.empty,
|
||||
annotation=p.annotation,
|
||||
) for p in signature.parameters
|
||||
]
|
||||
|
||||
|
||||
def is_class_instance(obj):
|
||||
"""Like inspect.* methods."""
|
||||
|
||||
Reference in New Issue
Block a user