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
Apologies if this is intentional behaviour instead of a bug. If it is, I couldn't find it in the changelog related to the type-checking of partial() that came with 1.11. So this issue might serve as a documentation of workarounds, too.
Bug Report
Prior to version 1.11 of mypy, the arguments passed to functools.partial() were not checked. With the newly introduced checks, passing in optional arguments by unpacking a dictionary does no longer work. **dict[str, str] (for example) is instead thought to refer to the first positional argument, which might have an entirely different type.
For a recent example from GitHub Actions in our repository, please see here.
For future reference: the second workaround in the above example was inspired by stackoverflow.
Not sure if there is any way mypy could distinguish between a **dict[str, str] being the correct type for the first positional argument or this argument not being specified for this partial object. That would be great, though.
Actual Behavior
From the playground example: main.py:15: error: Argument 1 to "foo" has incompatible type "**dict[str, str]"; expected "int" [arg-type].
Your Environment
Not sure if this is necessary with the playground example provided above. Please let me know if it is. For the playground example, I used mypy 1.11.0 with Python 3.12 and none of the options.
The text was updated successfully, but these errors were encountered:
Thanks for the thorough issue and discussing the workarounds. This is is basically preexisting mypy behaviour that is exposed now that we actually check functools.partial at all:
kwargs: dict[str, str] = {"key": "lorem", "name": "ipsum"}
def foo2(key: str | None = None, name: str | None = None, value: int | None = None): ...
foo2(**kwargs) # mypy complains because it doesn't know what keys kwargs are, and if there is a "value" in kwargs then there will be a TypeError
There are several duplicate issues about the choice to be sound here, see e.g. #17642
Apologies if this is intentional behaviour instead of a bug. If it is, I couldn't find it in the changelog related to the type-checking of
partial()
that came with 1.11. So this issue might serve as a documentation of workarounds, too.Bug Report
Prior to version 1.11 of mypy, the arguments passed to
functools.partial()
were not checked. With the newly introduced checks, passing in optional arguments by unpacking a dictionary does no longer work.**dict[str, str]
(for example) is instead thought to refer to the first positional argument, which might have an entirely different type.For a recent example from GitHub Actions in our repository, please see here.
For future reference: the second workaround in the above example was inspired by stackoverflow.
To Reproduce
Please see https://mypy-play.net/?mypy=1.11.0&python=3.12&gist=927391e497547426684526ac48c5f908 for a reproducible playground example of what I'm talking about.
Expected Behavior
Not sure if there is any way mypy could distinguish between a
**dict[str, str]
being the correct type for the first positional argument or this argument not being specified for thispartial
object. That would be great, though.Actual Behavior
From the playground example:
main.py:15: error: Argument 1 to "foo" has incompatible type "**dict[str, str]"; expected "int" [arg-type]
.Your Environment
Not sure if this is necessary with the playground example provided above. Please let me know if it is. For the playground example, I used mypy 1.11.0 with Python 3.12 and none of the options.
The text was updated successfully, but these errors were encountered: