Open
Description
I am working on removing dict
and **kwargs
hack from mypy after python/typeshed#8517 is merged.
But, I found a very confusing thing in how *args
and **kwargs
are checked.
Simple repro (all of the examples below work):
def some() -> None: ...
# args
some(*[1, 2])
args = [1, 2]
some(*args)
# kwargs
some(**{'a': 1})
kw = {'a': 2}
some(**kw)
All of these would raise TypeError
in runtime.
I think that the main idea was to allow calls like some(*[])
and some(**{})
which are fine in runtime.
This affects how overloads are selected in complex cases like:
class dict2(Generic[KT, VT]):
@overload
def __init__(self, __iterable: Iterable[Tuple[KT, VT]]) -> None: pass
@overload
def __init__(self: "dict2[str, VT]", __iterable: Iterable[Tuple[str, VT]], **kwargs: VT) -> None: pass
it = [(1, 'x')]
kw = {'x': 'y'}
reveal_type(dict2(it, **kw))
It looks like the second @overload
will raise an error: Iterable[Tuple[str, VT]]
is required, but Iterable[Tuple[int, str]]
is given.
But it does not, because of how **kwargs
are silently ignored. So, first @overload
always matches.
This is broken, if you ask me 😢