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: inspect.getcallargs sees optional arg to builtin as required
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Udi Meiri, brett.cannon, pablogsal, xtreak, yselivanov
Priority: normal Keywords:

Created on 2019-05-15 02:03 by Udi Meiri, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg342529 - (view) Author: Udi Meiri (Udi Meiri) Date: 2019-05-15 02:03
$ python3.7
Python 3.7.3rc1 (default, Mar 13 2019, 11:01:15) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect

>>> inspect.getfullargspec(str.strip)
FullArgSpec(args=['self', 'chars'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})
>>> inspect.signature(str.strip)
<Signature (self, chars=None, /)>

>>> inspect.signature(str.strip).bind('a')
<BoundArguments (self='a')>
>>> inspect.getcallargs(str.strip, 'a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/inspect.py", line 1372, in getcallargs
    _missing_arguments(f_name, req, True, arg2value)
  File "/usr/lib/python3.7/inspect.py", line 1302, in _missing_arguments
    "" if missing == 1 else "s", s))
TypeError: strip() missing 1 required positional argument: 'chars'
msg342551 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-05-15 07:09
This not reproducible on master and seems to fixed as part of PEP 570 related changes. Bisecting gives me d5d2b4546939b98244708e5bb0cfccd55b99d244 . Before d5d2b4546939b98244708e5bb0cfccd55b99d244 it produces an internal index error. I can reproduce the reported TypeError before PEP 570 was merged. I guess it's working perhaps as an unintended effect of the commit and internal error tells me it was not tested. Perhaps it's good to add a test for this? Note the change in fullargspec output between commits. Adding Pablo who will have better context.

➜  cpython git:(d5d2b45469) ./python.exe -c 'import inspect; print(inspect.getfullargspec(str.strip)); print(inspect.getcallargs(str.strip, "a"))'
/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/inspect.py:1114: DeprecationWarning: Use inspect.signature() instead of inspect.getfullargspec()
  warnings.warn("Use inspect.signature() instead of inspect.getfullargspec()",
FullArgSpec(args=['self', 'chars'], varargs=None, varkw=None, defaults=(None,), kwonlyargs=[], kwonlydefaults=None, annotations={})
{'self': 'a', 'chars': None}

d5d2b45469~1 commit

➜  cpython git:(81c5a90595) ./python.exe -c 'import inspect; print(inspect.getfullargspec(str.strip)); print(inspect.getcallargs(str.strip, "a"))'
FullArgSpec(args=[], varargs=None, varkw=None, defaults=(None,), posonlyargs=['self', 'chars'], kwonlyargs=[], kwonlydefaults=None, annotations={})
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/inspect.py", line 1365, in getcallargs
    arg2value[posonlyargs[i]] = positional[i]
IndexError: tuple index out of range
msg342585 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-05-15 16:52
Also note that inspect.getcallargs() has been deprecated since Python 3.5: https://docs.python.org/3/library/inspect.html#inspect.getcallargs.

Since the function is deprecated I'm closing as "won't fix".
History
Date User Action Args
2022-04-11 14:59:15adminsetgithub: 81101
2019-05-15 16:52:29brett.cannonsetstatus: open -> closed

nosy: + brett.cannon
messages: + msg342585

resolution: wont fix
stage: resolved
2019-05-15 07:09:34xtreaksetnosy: + pablogsal, xtreak
messages: + msg342551
2019-05-15 06:17:29SilentGhostsetnosy: + yselivanov
2019-05-15 02:03:29Udi Meiricreate