<div dir="auto">It's very important that f(z=5) Raises an exception if z is not an argument.<div dir="auto"><br></div><div dir="auto">For your case, I'd do a wrapper, instead lf calling f(z=5) you can call UniversalCall(f, x=1, y=2, z=5) if you want to specify it on the caller side.</div><div dir="auto"><br></div><div dir="auto">Or else, you can create a decorator :</div><div dir="auto"><br></div><div dir="auto">@universal_callable</div><div dir="auto">def f(x, y):</div><div dir="auto">    ...</div><div dir="auto"><br></div><div dir="auto">f(x=1, y=2, z=5)  # works !</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 24 Dec 2018, 11:21 李默 <<a href="mailto:phylimo@163.com">phylimo@163.com</a> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

    

<div>

<div style="font-family:Helvetica,Helvetica,微软雅黑,宋体;line-height:1.6">
    <div></div>

<div style="font-family:Helvetica,Helvetica,微软雅黑,宋体;line-height:1.6">
    <div></div><div style="line-height:1.7"><div style="color:rgb(0,0,0);font-size:14px"><font face="Consolas">I am having an idea on loosing the argument validity check when passing the function arguments in keyword way. </font></div><div style="color:rgb(0,0,0);font-size:14px"><font face="Consolas">For example:</font></div><div style="color:rgb(0,0,0);font-size:14px"><span class="m_2797748599284086478pl-k" style="white-space:pre-wrap"><font face="Consolas">-------------------------------</font></span></div><div style="color:rgb(0,0,0);font-size:14px"><font face="Consolas"><span class="m_2797748599284086478pl-k" style="white-space:pre-wrap">def</span><span style="white-space:pre-wrap"> </span><span class="m_2797748599284086478pl-en" style="white-space:pre-wrap">f</span><span style="white-space:pre-wrap">(</span><span class="m_2797748599284086478pl-smi" style="white-space:pre-wrap">x</span><span style="white-space:pre-wrap">, </span><span class="m_2797748599284086478pl-smi" style="white-space:pre-wrap">y</span><span style="white-space:pre-wrap">):</span></font></div><div><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">    <span class="m_2797748599284086478pl-c1">print</span>(x, y)
<span class="m_2797748599284086478pl-k">def</span> <span class="m_2797748599284086478pl-en">call_f</span>():
    f(<span class="m_2797748599284086478pl-v">x</span><span class="m_2797748599284086478pl-k">=</span><span class="m_2797748599284086478pl-c1">7</span>, <span class="m_2797748599284086478pl-v">y</span><span class="m_2797748599284086478pl-k">=</span><span class="m_2797748599284086478pl-c1">9</span>, <span class="m_2797748599284086478pl-v">z</span><span class="m_2797748599284086478pl-k">=</span><span class="m_2797748599284086478pl-c1">9</span>)
<br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">call_f()</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">------------------------------</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">In the current of python, the extra pass of 'z' would let the interpreter raise an exception and stop work.  My idea is that the interpreter need not stop because all the needed args are completely provided.  Of course for this toy example, 'f' can be define as  f(x, y, **kwargs) to achieve the same goal.  However,  essentially it is reasonably to keep interpreter going as long as enough args are passed.  And this modification can bring more freedom of programming. </font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">Think about the following situations:</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><span style="font-size:24px">situation 1) </span>there are many 'f's written by other people, and their args are very similar and your job is to run each of them to get some results.</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">---------------------</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">##########code by others:</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">def f0():
        ...
def f1(x):
        ...
def f2(x, y):
        ...
def f3(x, y, z):
        ...</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">#if passing extra args are valid, you can run all the functions in the following way, which is very compact and easy to read. </font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">def test_universal_call():</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"> funcs = [f0, f1, f2, f3]
        args = {'x':1, 'y':5, 'z':8}
        for f in funcs:
                f(**args)</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">------------------</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><span style="font-size:24px">situation 2)</span> there are several steps for make one product, each step is in an individual function and needs different args.</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">------------------</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">def make_oil(oil):
        ...</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">def make_water( water):
        ...</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">def make_powder(powder):
        ...</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">## if passing extra args are valid, you can run all the functions in the following way, which is very compact and easy to read. </font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">def dish():
        procedures = [make_oil, make_water, make_powder]</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">    args = {'oil' : 1, 'water': 10, 'powder': 4}
        for f in procedures:
                f(**args)</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">---------------</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="width:1610.25px"><font face="Consolas"><font color="#000000">This idea is different from **kwargs. **kwargs are used when user wants to record all the keywords passed. This idea is that even if the user doesn’t want to record the arguments, that extra pass of keyword arguments wont<span>’</span>t cause an exception.</font></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">Sorry for bothering you guys if this is a stupid idea.</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">Happy to hear your suggestions. </font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas">Li Mo</font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"><br></font></pre><pre style="color:rgb(0,0,0);font-size:14px;width:1610.25px"><font face="Consolas"> </font></pre></div></div><font face="Consolas"><br><br><span title="neteasefooter"><p> </p></span></font>
</div>
</div>
</div>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>