forked from VimPlug/jedi
Merge branch 'add-partialmethod' of https://github.com/ffe4/jedi
This commit is contained in:
@@ -471,13 +471,12 @@ def collections_namedtuple(value, arguments, callback):
|
||||
return ValueSet([ClassValue(inference_state, parent_context, generated_class)])
|
||||
|
||||
|
||||
class PartialObject(object):
|
||||
def __init__(self, actual_value, arguments):
|
||||
class PartialObject(ValueWrapper):
|
||||
def __init__(self, actual_value, arguments, instance=None):
|
||||
super(PartialObject, self).__init__(actual_value)
|
||||
self._actual_value = actual_value
|
||||
self._arguments = arguments
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self._actual_value, name)
|
||||
self._instance = instance
|
||||
|
||||
def _get_function(self, unpacked_arguments):
|
||||
key, lazy_value = next(unpacked_arguments, (None, None))
|
||||
@@ -493,6 +492,8 @@ class PartialObject(object):
|
||||
return []
|
||||
|
||||
arg_count = 0
|
||||
if self._instance is not None:
|
||||
arg_count = 1
|
||||
keys = set()
|
||||
for key, _ in unpacked_arguments:
|
||||
if key is None:
|
||||
@@ -501,13 +502,16 @@ class PartialObject(object):
|
||||
keys.add(key)
|
||||
return [PartialSignature(s, arg_count, keys) for s in func.get_signatures()]
|
||||
|
||||
def py__get__(self, instance, class_value):
|
||||
return ValueSet([PartialObject(self._actual_value, self._arguments, self._instance)])
|
||||
|
||||
def py__call__(self, arguments):
|
||||
func = self._get_function(self._arguments.unpack())
|
||||
if func is None:
|
||||
return NO_VALUES
|
||||
|
||||
return func.execute(
|
||||
MergedPartialArguments(self._arguments, arguments)
|
||||
MergedPartialArguments(self._arguments, arguments, self._instance)
|
||||
)
|
||||
|
||||
|
||||
@@ -523,15 +527,18 @@ class PartialSignature(SignatureWrapper):
|
||||
|
||||
|
||||
class MergedPartialArguments(AbstractArguments):
|
||||
def __init__(self, partial_arguments, call_arguments):
|
||||
def __init__(self, partial_arguments, call_arguments, instance=None):
|
||||
self._partial_arguments = partial_arguments
|
||||
self._call_arguments = call_arguments
|
||||
self._instance = instance
|
||||
|
||||
def unpack(self, funcdef=None):
|
||||
unpacked = self._partial_arguments.unpack(funcdef)
|
||||
# Ignore this one, it's the function. It was checked before that it's
|
||||
# there.
|
||||
next(unpacked)
|
||||
if self._instance is not None:
|
||||
yield None, LazyKnownValue(self._instance)
|
||||
for key_lazy_value in unpacked:
|
||||
yield key_lazy_value
|
||||
for key_lazy_value in self._call_arguments.unpack(funcdef):
|
||||
@@ -545,6 +552,15 @@ def functools_partial(value, arguments, callback):
|
||||
)
|
||||
|
||||
|
||||
def functools_partialmethod(value, arguments, callback):
|
||||
return ValueSet(
|
||||
# XXX last argument is a placeholder. See:
|
||||
# https://github.com/davidhalter/jedi/pull/1522#discussion_r392474671
|
||||
PartialObject(instance, arguments, True)
|
||||
for instance in value.py__call__(arguments)
|
||||
)
|
||||
|
||||
|
||||
@argument_clinic('first, /')
|
||||
def _return_first_param(firsts):
|
||||
return firsts
|
||||
@@ -742,6 +758,7 @@ _implemented = {
|
||||
},
|
||||
'functools': {
|
||||
'partial': functools_partial,
|
||||
'partialmethod': functools_partialmethod,
|
||||
'wraps': _functools_wraps,
|
||||
},
|
||||
'_weakref': {
|
||||
|
||||
Reference in New Issue
Block a user