[Python-ideas] Keyword only argument on function call
Jonathan Fine
jfine2358 at gmail.com
Wed Sep 12 09:23:34 EDT 2018
Steve Barnes suggested adding __params__, as in
> def a_method(self, cr, uid, ids, values, context=None):
> ...
> params = {k:v for k,v in __params__ if k in parent.a_method.keys()}
> # Possibly add some additional entries here!
> super(self, parent).a_method(**params)
Steve D'Aprano commented
> In single-threaded code, there's no problem here:
>
> A makes the first call;
> the interpreter sets function.__params__ to A's arguments;
> the function runs with A's arguments and returns;
I'm puzzled here. Steve B provided code fragment
for k,v in __params__
while Steve D provided code fragment
function.__params__
by which I think he meant in terms of Steve B's example
a_method.__params__
Perhaps Steve D thought Steve B wrote
def a_method(self, cr, uid, ids, values, context=None):
...
params = {k:v
for k,v in a_method.__params__ # Is this what Steve D
thought Steve B wrote?
if k in parent.a_method.keys()
}
# Possibly add some additional entries here!
super(self, parent).a_method(**params)
If Steve B had written this, then I would agree with Steve D's
comment. But as it is, I see no race condition problem, should
__params__ be properly implemented as a keyword identifier.
Steve D: Please clarify or explain you use of
function.__params__
Perhaps it was a misunderstanding.
By the way: I've made a similar mistake, on this very thread. So I
hope no great shame is attached to such errors.
<quote>
https://mail.python.org/pipermail/python-ideas/2018-September/053224.html
Summary: I addressed the DEFINING problem. My mistake. Some rough
ideas for the CALLING problem.
Anders has kindly pointed out to me, off-list, that I solved the wrong
problem. His problem is CALLING the function fn, not DEFINING fn.
Thank you very much for this, Anders.
</quote>
--
Jonathan
More information about the Python-ideas
mailing list