Replies: 1 comment 3 replies
-
Unfortunately, mypy is not great at deriving the best type for the dict literal in this case. Try explicitly annotating the dict: kwargs: dict[str, Any] = {"p1": "abc", "timeout": 1.0} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I have a question regarding the typing of a function with keyword-only arguments:
I have the following function:
Which is called like this:
With the typehints as shown above, mypy fails on the first call with
Argument 2 to "send_command" has incompatible type "**Dict[str, object]"; expected "Optional[float]" [arg-type]
I tried to fix this by adding the following overloads:
However, with those overloads, mypy no longer detects the wrong type for the timeout parameter (third call from above). What would be the correct typehint for this function?
Beta Was this translation helpful? Give feedback.
All reactions