You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I saw this in real code, although I don't really understand the reason why this is done. Still, even though it's a bit weird, it's legal and I think mypy should allow it:
class Foo:
def __init__(self, a=1, b=2):
self.a = a
self.b = b
Foo(**{})
$ mypy foo.py
foo.py:7: error: Keywords must be strings
The text was updated successfully, but these errors were encountered:
Agreed -- the dict could be type-checked here with a context of Mapping[str, Any] and that would make the empty dict have the type Dict[str, Any] rather than Dict[<nothing>, <nothing>].
### Description
Closes#5580
Previously, the type of empty dicts are inferred as `dict[<nothing>, <nothing>]`, which is not a subtype of `Mapping[str, Any]`, and this has caused a false-positive error saying `Keywords must be strings`. This PR fixes it by inferring the types of double-starred arguments with a context of `Mapping[str, Any]`.
Closes#4001 and closes#9007 (duplicate)
Do not check for "too many arguments" error when there are any double-starred arguments. This will lead to some false-negavites, see my comment here: #4001 (comment)
### Test Plan
Added a simple test `testPassingEmptyDictWithStars`. This single test can cover both of the issues above.
I also modified some existing tests that were added in #9573 and #6213.
I saw this in real code, although I don't really understand the reason why this is done. Still, even though it's a bit weird, it's legal and I think mypy should allow it:
The text was updated successfully, but these errors were encountered: