Fix partialmethod issues

This commit is contained in:
Dave Halter
2020-03-14 01:20:10 +01:00
parent fd9a493868
commit 0888dd468f
3 changed files with 27 additions and 11 deletions

View File

@@ -502,9 +502,6 @@ class PartialObject(ValueWrapper):
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:
@@ -514,6 +511,14 @@ class PartialObject(ValueWrapper):
MergedPartialArguments(self._arguments, arguments, self._instance)
)
def py__get__(self, instance, class_value):
return ValueSet([self])
class PartialMethodObject(PartialObject):
def py__get__(self, instance, class_value):
return ValueSet([PartialObject(self._actual_value, self._arguments, instance)])
class PartialSignature(SignatureWrapper):
def __init__(self, wrapped_signature, skipped_arg_count, skipped_arg_set):
@@ -554,9 +559,7 @@ 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)
PartialMethodObject(instance, arguments)
for instance in value.py__call__(arguments)
)

View File

@@ -391,18 +391,22 @@ class X:
return a, b
a = functools.partialmethod(function, 0)
kw = functools.partialmethod(function, b=1.0)
just_partial = functools.partial(function, 1, 2.0)
#? int()
X().a('')[0]
#? str()
X().a('')[1]
#? int()
X.a('')[0]
# The access of partialmethods on classes are not 100% correct. This doesn't
# really matter, because nobody uses it like that anyway and would take quite a
# bit of work to fix all of these cases.
#? str()
X.a('')[0]
#?
X.a('')[1]
#? int()
#? X()
X.a(X(), '')[0]
#? str()
X.a(X(), '')[1]
@@ -414,7 +418,7 @@ tup[0]
tup[1]
tup = X.kw(1)
#? int()
#?
tup[0]
#? float()
tup[1]
@@ -425,6 +429,15 @@ tup[0]
#? float()
tup[1]
#? float()
X.just_partial('')[0]
#? str()
X.just_partial('')[1]
#? float()
X().just_partial('')[0]
#? str()
X().just_partial('')[1]
# -----------------
# functools Python 3.8

View File

@@ -100,7 +100,7 @@ class X:
(partialmethod_code + 'X().b(', 'func(b, c)'),
(partialmethod_code + 'X().c(', 'func(b)'),
(partialmethod_code + 'X().d(', None),
(partialmethod_code + 'X.c(', 'func(b)'),
(partialmethod_code + 'X.c(', 'func(a, b)'),
(partialmethod_code + 'X.d(', None),
]
)