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
Instance methods are misreporting the number of arguments #46768
Comments
Opening a new issue per Raymond's request at msg64764: """
It would be *much* more useful to direct effort improving the mis-
reporting of the number of arguments given versus those required for
instance methods:
>>> a.f(1, 2)
TypeError: f() takes exactly 1 argument (3 given)
""" I would suggest that this misreporting may be dear to old-beards It does not seem to be that hard to change the diagnostic to >>> a.f(1, 2)
TypeError: f() takes no arguments (2 given) but the novice users would much rather see "a.f() takes no arguments (2 Raymond, what would you say to "<class 'A' instance>.f() takes no |
Attached patch (issue2516poc.diff) presents proof-of-concept code which >>> a.f(1,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: <A object>.f() takes exactly 0 arguments (2 given) More effort is needed to make this patch ready: support default/keyword |
You have +1 from me to continue developing this patch. |
I am uploading another work in progress patch because the problem proved
Finally, let's revisit whether this mosquito deserves to die. After It is also possible that I simply fail to see a simpler solution. It PS: The patch breaks cProfile and several other tests that check error |
Guido, what's your opinion on this? Is this a bug, and should it be fixed? |
It's definitely a bug, but I think the reason it has been around so I was hoping for something along the lines of functions raising an |
On Thu, Apr 3, 2008 at 9:39 PM, Raymond Hettinger
What would you say to the following: def f(x):
pass
class X:
xf = f
x = X()
x.xf(1,2) --> TypeError: f() takes exactly 1 argument (3 given) Is this correct? ..
This would be my first choice for a clean solution as well. Since it
.. according to what metric? Are you talking about the amount of code |
The same subject on python-dev raised last month received positive feedbacks: |
All that is needed now is a working patch... :) |
Here is a similar issue which may be easier to fix: >>> def f(a, b=None, *, c=None, d=None):
... pass
>>> f(1,2,3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() takes at most 4 arguments (3 given) Should be "f() takes at most 2 positional arguments (3 given)" |
Fixed in r82220. |
Maybe I'm misunderstanding what issue we're talking about here, but wasn't this supposed to be fixed? giampaolo@ubuntu:~/svn/python-3.2$ python3.2
Python 3.2a0 (py3k:82220M, Jun 25 2010, 21:38:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def foo(self, x):
... pass
...
>>> A().foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() takes exactly 2 arguments (1 given)
>>> |
I presume Benjamin meant he fixed the special case Alexander reported. |
This seems to have been fixed by now, on 3.11 I get this: >>> class A:
... def foo(self, x): pass
...
>>> A().foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: A.foo() missing 1 required positional argument: 'x' |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: