Issue 20817: inspect.getcallargs() raises the wrong error if 3+ arguments are missing (original) (raw)

Issue20817

Created on 2014-03-01 16:35 by jlowin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue20817.patch jlowin,2014-03-01 16:38 review
Messages (4)
msg212514 - (view) Author: Jeremiah Lowin (jlowin) * Date: 2014-03-01 16:35
If inspect.getcallargs() is called on a function and three or more arguments are missing, an IndexError is raised instead of the expected TypeError. This bug is present in Python 3.3 and 3.4.0 rc1 (5e05d7d3db9c). However, it worked as expected in Python 2.7.6. Example: >>> import inspect >>> def fn(a, b, c): >>> pass >>> inspect.getcallargs(fn) Result: IndexError: tuple index out of range Expected: TypeError: fn() missing 3 required positional arguments: 'a', 'b' and 'c'
msg212515 - (view) Author: Jeremiah Lowin (jlowin) * Date: 2014-03-01 16:38
The bug is caused by a list of names not getting properly expanded when generating the error message. This patch fixes it (simply by adding a * in the appropriate place) and tests that a TypeError, not an IndexError, is raised.
msg214988 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-27 22:45
New changeset 35302cc4fc93 by Yury Selivanov in branch 'default': inspect: Fix getcallargs() to fail correctly if more than 3 args are missing. http://hg.python.org/cpython/rev/35302cc4fc93 New changeset 9f06cbb7962b by Yury Selivanov in branch '3.4': inspect: Fix getcallargs() to fail correctly if more than 3 args are missing. http://hg.python.org/cpython/rev/9f06cbb7962b
msg214989 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-03-27 22:46
Fixed for 3.4.1 and 3.5. Thanks for the contribution!
History
Date User Action Args
2022-04-11 14:57:59 admin set github: 65016
2014-03-27 22:46:06 yselivanov set messages: +
2014-03-27 22:45:42 python-dev set status: open -> closednosy: + python-devmessages: + resolution: fixedstage: resolved
2014-03-01 18:39:44 yselivanov set assignee: yselivanovnosy: + larry, yselivanov, ncoghlan
2014-03-01 16:38:40 jlowin set files: + issue20817.patchkeywords: + patchmessages: +
2014-03-01 16:35:04 jlowin create