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
7 changes: 6 additions & 1 deletion pytype/overlays/functools_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ def get_signatures(self) -> Sequence[function.Signature]:
for name, value, _ in sig.iter_args(args):
if value is None:
continue
if sig.param_names.index(name) < sig.posonly_count:
if name == sig.varargs_name or name == sig.kwargs_name:
continue # Nothing to do for packed parameters.
if (
name not in sig.param_names or
sig.param_names.index(name) < sig.posonly_count
):
# The parameter is positional-only, meaning that it cannot be
# overwritten via a keyword argument. Remove it.
bound_param_names.add(name)
Expand Down
27 changes: 27 additions & 0 deletions pytype/tests/test_attr2.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,33 @@ class Foo:
assert_type(foo.x, int)
""")

def test_partial_with_star_args_as_converter(self):
self.Check("""
import attr
import functools
def f(*args: str) -> str:
return "".join(args)
@attr.s
class Foo:
x = attr.ib(converter=functools.partial(f, "foo", "bar"))
foo = Foo(x=0)
assert_type(foo.x, str)
""")

def test_partial_as_converter_with_factory(self):
# This is a smoke test for signature construction in the functools overlay.
self.Check("""
import collections
import functools
import attr
@attr.s(auto_attribs=True)
class Foo(object):
x = attr.ib(
factory=dict,
converter=functools.partial(collections.defaultdict, lambda: 0),
)
""")

def test_partial_overloaded_as_converter(self):
self.Check("""
import attr
Expand Down
Loading