Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pytype/overlays/functools_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ def __init__(self, ctx: "context.Context", module: str):
def new_slot(
self, node, cls, func, /, *args, **kwargs
) -> tuple[cfg.CFGNode, cfg.Variable]:
# We are not using ``cls``, because it is set to unsolvable when
# functools.partial is called with *args.
del cls

# Make sure the call is well typed before binding the partial
new = self.ctx.convert.convert_pytd_function(self._pytd_new)
_, specialized_obj = function.call_function(
self.ctx,
node,
new.to_variable(node),
function.Args(
(cls, func, *args),
(self.to_variable(node), func, *args),
kwargs,
call_context.starargs,
call_context.starstarargs,
Expand All @@ -65,8 +69,7 @@ def new_slot(
)
[specialized_obj] = specialized_obj.data
type_arg = specialized_obj.get_formal_type_parameter("_T")
[cls] = cls.data
cls = abstract.ParameterizedClass(cls, {"_T": type_arg}, self.ctx)
cls = abstract.ParameterizedClass(self, {"_T": type_arg}, self.ctx)
obj = bind_partial(node, cls, func, args, kwargs, self.ctx)
return node, obj.to_variable(node)

Expand Down
14 changes: 14 additions & 0 deletions pytype/tests/test_functions1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,20 @@ def f(a, b) -> None: ...
""",
)

def test_functools_partial_star(self):
self.Check("""
from typing import Any
import functools
def f() -> int :
return 42
def test(*args):
assert_type(functools.partial(*args), functools.partial[Any])

# This is WAI in pytype, since *args currently overwrite *all* other
# arguments, including the ones bound positionally prior to *args.
assert_type(functools.partial(f, *args), functools.partial[Any])
""")

def test_functools_partial_kw(self):
self.Check("""
import functools
Expand Down
Loading