-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Improve error messages for unexpected keyword arguments in overloaded functions #20592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Improve error messages for unexpected keyword arguments in overloaded functions #20592
Conversation
This comment has been minimized.
This comment has been minimized.
| def f(foobar: Union[int, str]) -> None: | ||
| pass | ||
|
|
||
| f(fobar=1) # E: Unexpected keyword argument "fobar" for overloaded function "f" defined on line 4; did you mean "foobar"? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't report the line number here. It could be useful to report it, but we generally use a note, since the function could be in a different file so line number by itself isn't sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, I'll exclude the line number from the error messaging
| pass | ||
|
|
||
| f(fobar=1) # E: Unexpected keyword argument "fobar" for overloaded function "f" defined on line 4; did you mean "foobar"? | ||
| f(random=[1,2,3]) # E: Unexpected keyword argument "random" for overloaded function "f" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional test ideas:
- Test multiple invalid keyword arguments
- Test both invalid keyword argument and incompatible positional argument
- Test both valid an invalid keyword arguments in the same call
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
08e94c3 to
f3067fd
Compare
|
Diff from mypy_primer, showing the effect of this PR on open source code: prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/futures.py:224: error: Unexpected keyword argument "_sync" for overloaded function "result" of "State" [call-overload]
+ src/prefect/utilities/engine.py:764: error: Unexpected keyword argument "_sync" for overloaded function "result" of "State" [call-overload]
+ src/prefect/task_engine.py:529: error: Unexpected keyword argument "_sync" for overloaded function "result" of "State" [call-overload]
scipy (https://github.com/scipy/scipy)
+ scipy/sparse/linalg/tests/test_interface.py:306: error: Unexpected keyword argument "axis" for overloaded function "__call__" of "_GUFunc_Nin2_Nout1" [call-overload]
+ scipy/sparse/linalg/tests/test_interface.py:307: error: Unexpected keyword argument "axis" for overloaded function "__call__" of "_GUFunc_Nin2_Nout1" [call-overload]
xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_plot.py:1167: error: Unexpected keyword argument "start" for overloaded function "arange" [call-overload]
+ xarray/tests/test_plot.py:1168: error: Unexpected keyword argument "start" for overloaded function "arange" [call-overload]
|
|
Can you investigate the mypy_primer diff? Were there no errors reported in the past, or do we now generate multiple errors for some calls, and are the new errors valid? |
This PR improves error messages when calling overloaded functions with unexpected keyword arguments, making it easier to identify and fix typos.