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
/home/veith/.config/JetBrains/PyCharm2022.1/scratches/scratch_7.py:10: error: The first argument to Callable must be a list of types or "..."
/home/veith/.config/JetBrains/PyCharm2022.1/scratches/scratch_7.py:10: error: Name "Signature.args" is not defined
/home/veith/.config/JetBrains/PyCharm2022.1/scratches/scratch_7.py:10: error: Name "Signature.kwargs" is not defined
/home/veith/.config/JetBrains/PyCharm2022.1/scratches/scratch_7.py:29: error: Unexpected keyword argument "a"
/home/veith/.config/JetBrains/PyCharm2022.1/scratches/scratch_7.py:29: error: Unexpected keyword argument "b"
/home/veith/.config/JetBrains/PyCharm2022.1/scratches/scratch_7.py:29: error: Unexpected keyword argument "c"
There are two errors here, I am not sure how related they are, so I have them both in this ticket:
The type alias on top is not accepted, because it can not relate the Signature ParamSpec within the Callable (I assume).
When calling the function, it does not detect that a,b,c are actually valid keyword arguments to foo.
Your Environment
Mypy version used: mypy 0.950 (compiled: yes)
Mypy command-line flags: None, but if you add --strict it adds the error /home/veith/.config/JetBrains/PyCharm2022.1/scratches/scratch_7.py:16: error: Missing type parameters for generic type "TakesFunctionWithArguments"
Callable does not support *args or **kwargs parameters, so you cannot use P.args and P.kwargs within a Callable. You would need to use a callback protocol here instead.
Also, TakesFunctionWithArguments in your code sample is a generic type alias that accepts two type arguments, but when you use it, you are not providing any type arguments. That means mypy will assume Any for T and ... for Signature. That's probably not what you intend here.
Here's a modified sample that does type check correctly in mypy:
Exactly as Eric says: this kind of callable is inexpressible using the shorthand Callable[<params>, <return>] syntax. A callback protocol is the way to go.
Bug Report
Defining a type that says: "I am a function that takes a function and its arguments" does not get accepted by mypy.
To Reproduce
Expected Behavior
This should type check correctly. It runs fine.
Actual Behavior
There are two errors here, I am not sure how related they are, so I have them both in this ticket:
Your Environment
/home/veith/.config/JetBrains/PyCharm2022.1/scratches/scratch_7.py:16: error: Missing type parameters for generic type "TakesFunctionWithArguments"
Possibly related to #12595
The text was updated successfully, but these errors were encountered: