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
Adding more information to "Too Few Arguments" #9796
Conversation
I am sorry I don't have much knowledge about tests. Do I need to manually change all the tests because "Too few arguments" error is invoked plenty of times. Forgive me for sounding stupid I am new. |
also checking for None
Yes but you can do it smartly. Using |
And you also need to fix your code formatting to pass flake8 tests |
None of Also I integrated flake8 with my Visual Studio code. It would be nice if you could help me figure out the flake8 arguments/settings used with mypy (other than max-length, I am getting many errors that are ignored by mypy's flake8, so what all am I supposed to add to |
To submit a PR to mypy, all you need is to run For the This may help you have a better understanding of mypy testing workflow: https://github.com/python/mypy/blob/master/test-data/unit/README.md |
Thanks a lot and sorry for not giving the readme a read. |
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.
The change to existing code needs some second thoughts, see comments below.
test-data/unit/check-callable.test
Outdated
@@ -110,7 +110,7 @@ from typing import Callable, Union | |||
x = 5 # type: Union[int, Callable[[], None], Callable[[int], None]] | |||
|
|||
if callable(x): | |||
x() # E: Too few arguments | |||
x() # E: Missing positional argument |
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.
This error message should not apply to Callable IMO. The current one would do the job.
test-data/unit/check-classes.test
Outdated
@@ -3751,7 +3751,7 @@ int.__eq__(int) | |||
int.__eq__(3, 4) | |||
[builtins fixtures/args.pyi] | |||
[out] | |||
main:33: error: Too few arguments for "__eq__" of "int" | |||
main:33: error: Missing positional arguments |
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.
same here
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.
I understand callable and lamda functions. But here are you pointing at magic methods?
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.
If I make my message something as Missing positional argument for call to "__eq__" of "int"
then the only difference would be language. So is it about language or the missing function name here?
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.
I think the original language is sufficient. The new one does not make much improvement.
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.
So I think where the information about the arguments to be provided is not available, i.e. the message is just "Missing positional argument", there we can leave it to the old language? Should I code it that way?
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.
exactly. For callables, lambdas, magic methods (and maybe more), the names of the arguments are unknown so staying to the old language is totally fine. Let's improve the language only for user-defined functions and methods in this PR. If there's a need to improve other cases in the future, we can do them later in separate PRs.
@@ -623,7 +623,7 @@ reveal_type((lambda x, y: x + y)(1, 2)) # N: Revealed type is 'builtins.int' | |||
reveal_type((lambda s, i: s)(i=0, s='x')) # N: Revealed type is 'Literal['x']?' | |||
reveal_type((lambda s, i: i)(i=0, s='x')) # N: Revealed type is 'Literal[0]?' | |||
reveal_type((lambda x, s, i: x)(1.0, i=0, s='x')) # N: Revealed type is 'builtins.float' | |||
(lambda x, s, i: x)() # E: Too few arguments | |||
(lambda x, s, i: x)() # E: Missing positional arguments |
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.
same for lambda functions
@@ -214,7 +214,7 @@ main:5: error: Invalid "type: ignore" comment [syntax] | |||
|
|||
[case testErrorCodeArgKindAndCount] | |||
def f(x: int) -> None: pass # N: "f" defined here | |||
f() # E: Too few arguments for "f" [call-arg] | |||
f() # E: Missing positional argument "x" in call to "f" [call-arg] |
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.
this is a perfect example of what's expected in this PR IMO
Thanks for the updates! Can you verify the case in #9340? For example, use the following code(copied from the issue):
You may also make this a new test case. I did some verification locally and looks like the changes don't work on this segment. |
@TH3CHARLie I have tested the code in the issue #9340 and the new changes reflect. I made a new test case to check missing positional arguments using the code in the issue and it passes. |
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.
Thanks for the updates and verifications, looks good to me. However I am not sure I am 100% in sync with the expectations in #9340, @gvanrossum Would you mind taking a look if you have time?
Thanks a lot for your review and approval. |
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.
Hm, the number of tests that have to be fixed is a bit much, and in some cases the name of the missing argument isn't very useful, but I agree its most consistent. So weak +1.
Thanks for the review. I am merging this now but I'll keep an eye on this(and respond to any future feedbacks about it) since error messages are important and pervasive |
Description
Fixes #9340
As mentioned in the feature request, mypy now gives more information about the missing required arguments when creating an instance.
The problem was with the if statement that only gave information when the arguments provided were not empty and none. Removing that check gives information for calls with no argument too.
Before:
test.py:6: error: Too few arguments for "Foo"
After:
test.py:7: error: "Foo" missing 1 required positional argument: 'bar'
Test Plan
All tests passing