[issue22652] Add suggestion about keyword arguments to this error message: "builtins.TypeError: my_func() takes 1 positional argument but 2 were given"

2020-05-15 Thread A. Jesse Jiryu Davis


A. Jesse Jiryu Davis  added the comment:

If the patch requires a rewrite and its value is uncertain then I'll excuse 
myself from this issue.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: "builtins.TypeError: my_func() takes 1 positional argument but 2 were given"

2020-05-15 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

First, the code for checking arguments was significantly changed in recent 
versions. So if we are going to make these changes the patch should be not just 
rebased, but rewritten from zero.

Second, the error messages for wrong number of positional arguments are more 
diverse.

>>> def func(a, b=1): pass
... 
>>> func()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: func() missing 1 required positional argument: 'a'
>>> func(1, 2, 3)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: func() takes from 1 to 2 positional arguments but 3 were given

It differs when you pass less positional arguments than expected, and when 
there are optional positional parameters.

Third, when you pass incorrect number of keyword arguments, you get error 
either about missed keyword arguments (they names, not count), or about an 
unexpected keyword argument (with its name).

Forth, if you change error messages for Python implemented functions, don't 
forget about functions implemented in C. Those which use 
PyArg_ParseTupleAndKeywords (and variants), those which use Argument Clinic, 
and special cases like print(), sorted(), max().

Personally I think that the current error message is correct and complete. But 
if you want to improve it, remember that additional information should be 
correct, useful and consistent across different types of functions. Also, too 
verbose error message can have negative effect on comprehension. It should 
provide information necessary to identify the source of the error and do not 
distract from it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: "builtins.TypeError: my_func() takes 1 positional argument but 2 were given"

2020-05-14 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Also, python-ideas list is a good place to get more opinions (too many 
sometimes) on an enhancement proposal.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: "builtins.TypeError: my_func() takes 1 positional argument but 2 were given"

2020-05-14 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Serhiy, I am nosying you because you have worked on argument issues in the last 
year.

Minimal example: def f(a, *, b): pass.  In 3.9.0a6,

>>> f(1,2) # ... Same as 5 years ago.
  TypeError: f() takes 1 positional argument but 2 were given

My first inclination was that this is sufficient information.  But ...

>>> f(1,2,b=3) # ...
  TypeError: f() takes 1 positional argument but 2 positional arguments (and 1 
keyword-only argument) were given

The simple message is equally sufficiant here, but more is given, and it seems 
strange to not then give the equivalent for for 'takes'.  So the patch to add 
more seems plausible (but I am not one to carefully review C code).

Jesse, if you still want your patch, possibly updated, considered, please make 
a PR.

We now also have positional-only arguments, and I am not sure how that affects 
my view on this issue.

--
nosy: +serhiy.storchaka, terry.reedy
versions: +Python 3.9 -Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: builtins.TypeError: my_func() takes 1 positional argument but 2 were given

2015-04-13 Thread A. Jesse Jiryu Davis

A. Jesse Jiryu Davis added the comment:

Attached patch adds and N keyword-only argument(s) to the TypeError message 
if a function takes keyword-only arguments and the wrong number of positional 
arguments is provided.

--
keywords: +patch
nosy: +emptysquare
Added file: http://bugs.python.org/file38929/issue22652.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22652
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: builtins.TypeError: my_func() takes 1 positional argument but 2 were given

2015-04-12 Thread Ram Rachum

Ram Rachum added the comment:

ztane: I don't think so. You're taking attention away from the and 
keyword-only arguments, where in fact this is the piece of information that's 
likely to save the user the most time, so therefore it should get more 
attention.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22652
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: builtins.TypeError: my_func() takes 1 positional argument but 2 were given

2015-04-12 Thread R. David Murray

R. David Murray added the comment:

These messages are generated generically, and just because the proble you hit 
was this one, doesn't someone else won't hit it for a different reason and have 
other requirements.  (Note that these messages are *way* better than they used 
to be, thanks to Benjanmi Peterson's work).

The suggestion of adding that the function takes keyword only argumentgs seems 
reasonable to me, though I'd have to look at Benjamin's code to make sure it 
makes sense (I thought it already mentioned what argments/types the function 
took).  As you say, it is low priority.

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22652
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: builtins.TypeError: my_func() takes 1 positional argument but 2 were given

2015-04-11 Thread Antti Haapala

Antti Haapala added the comment:

Would it be enough to just have the message say takes 1 positional argument 
and keyword-only arguments but 2 positional arguments were given? And this 
should of course for **kwargs too.

--
nosy: +ztane

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22652
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: builtins.TypeError: my_func() takes 1 positional argument but 2 were given

2014-11-18 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
stage:  - needs patch
type:  - enhancement

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22652
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: builtins.TypeError: my_func() takes 1 positional argument but 2 were given

2014-10-16 Thread Ram Rachum

New submission from Ram Rachum:

When programming, I just got this exception:

builtins.TypeError: my_func() takes 1 positional argument but 2 were given

After a couple of minutes of investigation I figured out that the problem is 
that the function has a `*` in its signature, so arguments must be specified as 
keyword arguments, not positional arguments.

It would be nice if the exception message would include some text to suggest 
that, like:

builtins.TypeError: my_func() takes 1 positional argument but 2 were given. 
If you were trying to use the keyword-only argument foo, please specify it as 
foo=value.

It's a little verbose and specific, but maybe it'll help people figure out this 
problem, especially newbies. We can have logic to show this message only if 
there are keyword-only arguments.

--
components: Interpreter Core
messages: 229521
nosy: cool-RR
priority: normal
severity: normal
status: open
title: Add suggestion about keyword arguments to this error message: 
builtins.TypeError: my_func() takes 1 positional argument but 2 were given
versions: Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22652
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: builtins.TypeError: my_func() takes 1 positional argument but 2 were given

2014-10-16 Thread Ram Rachum

Ram Rachum added the comment:

(I should note that I see this suggestion as low-priority, because it's very 
specific, so I'll completely understand if it's deemed to not be worth the 
added complexity.)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22652
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22652] Add suggestion about keyword arguments to this error message: builtins.TypeError: my_func() takes 1 positional argument but 2 were given

2014-10-16 Thread Benjamin Peterson

Changes by Benjamin Peterson benja...@python.org:


--
priority: normal - low

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22652
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com