[issue20816] inspect.getcallargs() attempts to iterate over None
New submission from Jeremiah Lowin: Tested in Python 3.3 and Python 3.4.0rc1 5e05d7d3db9c If a function has keyword-only arguments but no keyword-only defaults, then calling inspect.getcallargs with no arguments results in the wrong TypeError being raised. Example: >>> import inspect >>> def fn(*, a): >>>pass >>> inspect.getcallargs(fn) Result: TypeError: argument of type 'NoneType' is not iterable Expected Result: TypeError: fn() missing 1 required keyword-only argument: 'a' -- components: Library (Lib) messages: 212509 nosy: jlowin priority: normal severity: normal status: open title: inspect.getcallargs() attempts to iterate over None type: behavior versions: Python 3.3, Python 3.4 ___ Python tracker <http://bugs.python.org/issue20816> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20816] inspect.getcallargs() attempts to iterate over None
Jeremiah Lowin added the comment: I created a patch to resolve this. If a function has keyword-only arguments, then inspect.getcallargs checks if the argument is in kwonlydefaults. However, kwonlydefaults is None if no defaults were specified. In that situation, 'kwarg in kwonlydefaults' raises the TypeError. The quick fix is simply to test kwonlydefaults before testing if kwarg is in it. The test for this situation is a little verbose because a TypeError is expected and one is raised, just the wrong one, so I parse the error message. -- ___ Python tracker <http://bugs.python.org/issue20816> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20816] inspect.getcallargs() attempts to iterate over None
Jeremiah Lowin added the comment: Apologies, the patch is attached here. -- keywords: +patch Added file: http://bugs.python.org/file34260/issue20816.patch ___ Python tracker <http://bugs.python.org/issue20816> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20817] inspect.getcallargs() raises the wrong error if 3+ arguments are missing
New submission from Jeremiah Lowin: 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' -- components: Library (Lib) messages: 212514 nosy: jlowin priority: normal severity: normal status: open title: inspect.getcallargs() raises the wrong error if 3+ arguments are missing type: behavior versions: Python 3.3, Python 3.4 ___ Python tracker <http://bugs.python.org/issue20817> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20817] inspect.getcallargs() raises the wrong error if 3+ arguments are missing
Jeremiah Lowin added the comment: 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. -- keywords: +patch Added file: http://bugs.python.org/file34261/issue20817.patch ___ Python tracker <http://bugs.python.org/issue20817> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com