mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
Fix partialmethod issues
This commit is contained in:
@@ -502,9 +502,6 @@ class PartialObject(ValueWrapper):
|
|||||||
keys.add(key)
|
keys.add(key)
|
||||||
return [PartialSignature(s, arg_count, keys) for s in func.get_signatures()]
|
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):
|
def py__call__(self, arguments):
|
||||||
func = self._get_function(self._arguments.unpack())
|
func = self._get_function(self._arguments.unpack())
|
||||||
if func is None:
|
if func is None:
|
||||||
@@ -514,6 +511,14 @@ class PartialObject(ValueWrapper):
|
|||||||
MergedPartialArguments(self._arguments, arguments, self._instance)
|
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):
|
class PartialSignature(SignatureWrapper):
|
||||||
def __init__(self, wrapped_signature, skipped_arg_count, skipped_arg_set):
|
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):
|
def functools_partialmethod(value, arguments, callback):
|
||||||
return ValueSet(
|
return ValueSet(
|
||||||
# XXX last argument is a placeholder. See:
|
PartialMethodObject(instance, arguments)
|
||||||
# https://github.com/davidhalter/jedi/pull/1522#discussion_r392474671
|
|
||||||
PartialObject(instance, arguments, True)
|
|
||||||
for instance in value.py__call__(arguments)
|
for instance in value.py__call__(arguments)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -391,18 +391,22 @@ class X:
|
|||||||
return a, b
|
return a, b
|
||||||
a = functools.partialmethod(function, 0)
|
a = functools.partialmethod(function, 0)
|
||||||
kw = functools.partialmethod(function, b=1.0)
|
kw = functools.partialmethod(function, b=1.0)
|
||||||
|
just_partial = functools.partial(function, 1, 2.0)
|
||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
X().a('')[0]
|
X().a('')[0]
|
||||||
#? str()
|
#? str()
|
||||||
X().a('')[1]
|
X().a('')[1]
|
||||||
|
|
||||||
#? int()
|
# The access of partialmethods on classes are not 100% correct. This doesn't
|
||||||
X.a('')[0]
|
# really matter, because nobody uses it like that anyway and would take quite a
|
||||||
|
# bit of work to fix all of these cases.
|
||||||
#? str()
|
#? str()
|
||||||
|
X.a('')[0]
|
||||||
|
#?
|
||||||
X.a('')[1]
|
X.a('')[1]
|
||||||
|
|
||||||
#? int()
|
#? X()
|
||||||
X.a(X(), '')[0]
|
X.a(X(), '')[0]
|
||||||
#? str()
|
#? str()
|
||||||
X.a(X(), '')[1]
|
X.a(X(), '')[1]
|
||||||
@@ -414,7 +418,7 @@ tup[0]
|
|||||||
tup[1]
|
tup[1]
|
||||||
|
|
||||||
tup = X.kw(1)
|
tup = X.kw(1)
|
||||||
#? int()
|
#?
|
||||||
tup[0]
|
tup[0]
|
||||||
#? float()
|
#? float()
|
||||||
tup[1]
|
tup[1]
|
||||||
@@ -425,6 +429,15 @@ tup[0]
|
|||||||
#? float()
|
#? float()
|
||||||
tup[1]
|
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
|
# functools Python 3.8
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class X:
|
|||||||
(partialmethod_code + 'X().b(', 'func(b, c)'),
|
(partialmethod_code + 'X().b(', 'func(b, c)'),
|
||||||
(partialmethod_code + 'X().c(', 'func(b)'),
|
(partialmethod_code + 'X().c(', 'func(b)'),
|
||||||
(partialmethod_code + 'X().d(', None),
|
(partialmethod_code + 'X().d(', None),
|
||||||
(partialmethod_code + 'X.c(', 'func(b)'),
|
(partialmethod_code + 'X.c(', 'func(a, b)'),
|
||||||
(partialmethod_code + 'X.d(', None),
|
(partialmethod_code + 'X.d(', None),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user