[New-bugs-announce] [issue12356] more argument error improving

Benjamin Peterson report at bugs.python.org
Sat Jun 18 02:45:31 CEST 2011


New submission from Benjamin Peterson <benjamin at python.org>:

After completing #12265, it was pointed out to me that the error message is still not perfect:

>>> def f(a, b, c=3, d=4, e=6, f=3, g=32): pass
... 
>>> f(1, f=4, d=90)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() takes from 2 to 7 positional arguments but 3 were given

Here is a new patch.

Some samples:

>>> def f(a): pass
... 
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 1 required positional argument: 'a'
>>> def f(a, b): pass
... 
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 2 required positional arguments: 'a' and 'b'

>>> def f(a, b, c): pass
... 
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 3 required positional arguments: 'a', 'b', and 'c
>>> def f(a, b, c, d): pass
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 4 required positional arguments: 'a', 'b', 'c', and 'd'

Same with kwonly:

>>> def f(*, w): pass
... 
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 1 required keyword-only argument: 'w'
>>> def f(*, a, b, c, d, e): pass
... 
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 5 required keyword-only arguments: 'a', 'b', 'c', 'd', and 'e'

For too many positional arguments, the old (new) error is retained:

>>> def f(a): pass
... 
>>> f(1, 2, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() takes 1 positional argument but 3 were given
>>> f(3, 4, 5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() takes from 1 to 2 positional arguments but 3 were given

----------
components: Interpreter Core
files: argerror.patch
keywords: patch
messages: 138563
nosy: benjamin.peterson
priority: normal
severity: normal
stage: patch review
status: open
title: more argument error improving
type: feature request
versions: Python 3.3
Added file: http://bugs.python.org/file22399/argerror.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12356>
_______________________________________


More information about the New-bugs-announce mailing list