This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Display function signature in TypeErrors resulting from argument mismatches
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, eric.araujo, ezio.melotti, gpolo, madan.ram, r.david.murray
Priority: normal Keywords:

Created on 2013-11-27 10:10 by madan.ram, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg204569 - (view) Author: madan ram (madan.ram) Date: 2013-11-27 10:10
I found that it will be useful to show the list of function arguments using inspect module. When the function executed by the user in interpreter as "TypeError". 

ex: - 

>>def foo(a,b=4,c="hello"):
...     print a,b,c

>>foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() takes at least 2 arguments (0 given)

Rather the displaying like above it is will be much more readable to show as below.

>>foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() takes at least 1 arguments args=['a', 'b', 'c'], varargs=None, keywords=None, defaults=(4, 'hello') (0 given)

This will be advantageous when the user has forgotten what parameter to use for builtin function when working offline.
msg204588 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-27 14:33
That's much less readable than the output from pfydoc, which the user can access easily (via either help at the interpreter prompt or pydoc at the shell prompt).  So I'm -1 on this proposed change.
msg204596 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-11-27 15:15
While we don't print the whole signature, this is much improved in 3.3:

>>> def foo(a,b=4,c="hello"): pass
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() missing 1 required positional argument: 'a'
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 64009
2013-11-27 15:15:37benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg204596

resolution: rejected
2013-11-27 14:34:10r.david.murraysettype: enhancement
title: Adding a feature to python interpreter -> Display function signature in TypeErrors resulting from argument mismatches
2013-11-27 14:33:02r.david.murraysetnosy: + r.david.murray
messages: + msg204588
2013-11-27 10:18:32georg.brandlsetnosy: - georg.brandl

versions: - Python 3.3, Python 3.4
2013-11-27 10:12:09madan.ramsettitle: adding an feature to python interpreter -> Adding a feature to python interpreter
2013-11-27 10:10:45madan.ramcreate