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
{{ message }}
Repository navigation
Invalid ParamSpec usage in function with added kwargs not reported as error #14832
In first case the __call__ definition should be flagged as error.
In second case the behaviour should match the inline comments.
Actual Behavior
In first case no errors are found.
In second case foo is rejected due to named arguments (this violates PEP-612, but is easily fixable with __s arg name instead, as usual, error message can be improved here). while bar is accepted, also violating the PEP:
main.py:14: error: Incompatible return value type (got "Callable[[Arg(str, 's'), **P], None]", expected "Callable[[str, **P], None]") [return-value]
main.py:14: note: This is likely because "foo" has named arguments: "s". Consider marking them positional-only
Found 1 error in 1 file (checked 1 source file)
Your Environment
Mypy version used: master, 1.0.1
Mypy command-line flags: --strict and without it
Mypy configuration options from mypy.ini (and other config files): none
changed the title [-]Invalid ParamSpec usage not reported[/-][+]Invalid ParamSpec usage in function with added kwargs not reported as error[/+]on Mar 3, 2023
this code generates no issues in mypy 1.0.1 but pyright 1.1.339 correctly flags errors for each of cases 2 .. 5:
/tmp/paramspec_types_2.py
/tmp/paramspec_types_2.py:10:16 - error: "args" member of ParamSpec is valid only when used with *args parameter
/tmp/paramspec_types_2.py:10:28 - error: "kwargs" member of ParamSpec is valid only when used with **kwargs parameter
/tmp/paramspec_types_2.py:15:20 - error: "args" and "kwargs" members of ParamSpec must both appear within a function signature
/tmp/paramspec_types_2.py:20:23 - error: "args" and "kwargs" members of ParamSpec must both appear within a function signature
/tmp/paramspec_types_2.py:25:29 - error: Keyword parameter "a" cannot appear in signature after ParamSpec args parameter (reportGeneralTypeIssues)
5 errors, 0 warnings, 0 informations
Activity
[-]Invalid ParamSpec usage not reported[/-][+]Invalid ParamSpec usage in function with added kwargs not reported as error[/+]sterliakov commentedon Mar 3, 2023
This is the cause of #13966 - the invalid usage is not reported there.
nickzoic commentedon Dec 11, 2023
In general mypy doesn't seem to be picking up on errors around the 'rejected' behaviours, just silently ignoring the annotion?
Eg: the following code, case
f1is typed correctly butf2throughf5are all incorrect:this code generates no issues in mypy 1.0.1 but pyright 1.1.339 correctly flags errors for each of cases 2 .. 5:
flying-sheep commentedon Mar 4, 2024
See here for a discussion to make this happen: https://discuss.python.org/t/type-hints-for-kwarg-overrides/47196
Reject invalid ParamSpec locations (python#18278)