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: Incorrect application of func.__defaults__ by inspect's signature APIs
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, bup, yselivanov
Priority: normal Keywords:

Created on 2019-05-27 10:57 by bup, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg343613 - (view) Author: Dan Snider (bup) * Date: 2019-05-27 10:57
The interpreter matches the values in func.__defaults__ with the calculated positional argument names "right-to-left", while inspect does does so "left-to-right". In every day usage, for "normal" functions, generated by the compiler from "normal", hand-typed source code, it is impossible to encounter this. 

>>> def f(x): return x
>>> x.__defaults__ = (1,2,3)
>>> inspect.getfullargspec(f)
FullArgSpec(args=['x'], varargs=None, varkw=None, defaults=(1,), kwonlyargs=[], kwonlydefaults=None, annotations={})
>>> f()
3
>>> f.__defaults__
(1, 2, 3)



So I'll be honest: I've submitted this particularly inconsequential bug report as a pretext to ask for advice on how to contribute here, because frankly, this is getting out of hand. While I haven't counted, it would not surprise me if I have more than 20 open tickets on here currently. While that may not be uncommon it does bother me slightly. And those are just the ones I had the time  and/or remembered to to submit a ticket for. There's another 45-50 whose location I'm certain of, fully documented and fixed.

If this little digression is against some sort of rules, then I apologize now and must concur. That being said, despite my lack of a formal education, my seemingly never-ending quest to push the interpreter to its limits, hunting for the most esoteric of optimizations (and flaws) has turned out to be quite the hobby. I've aquired a great deal of knowledge on the subject which, in the grand scheme of things is being wasted, as the only thing of actual significance I could see myself doing with it is using it to contribute here.

But when I consider the amount of time I've wasted on the matter already on this, I've totally lost faith in my own ability to judge what might constitute a good resource on the subject of GH. The other venues I'm aware of haven't been helpful to me so I don't even bother with them anymore. I will read the dev guide again, since it has been a while. However to my recollection the problems I had with it wasn't technicality per se, it was that it was it was full of totally foreign terminology to me, with words and phrases such as "pulling on this while the squisher of that squasher pushes on that".
msg357397 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-11-24 15:36
As mentioned in docs, getfullargspec is based on signature() and signature objects doesnt keep record of all defaults. It tries to map defaults with parameters but if you have less default then total parameter amount it will discard rest of defaults. IMHO this isn't a bug.
History
Date User Action Args
2022-04-11 14:59:15adminsetgithub: 81244
2019-11-24 15:36:38BTaskayasetnosy: + yselivanov, BTaskaya
messages: + msg357397
2019-05-27 10:57:38bupcreate