<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 10, 2018 at 11:00 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br></span>
In my day job I spend a lot of time writing/customizing modules for a framework called OpenERP (now Odoo*).  Those modules are all subclasses, and most work will require updating at least a couple parent methods -- so most calls look something like:<br>
<br>
  def a_method(self, cr, uid, ids, values, context=None):<br>
    ...<br>
    super(self, parent).a_method(cr, uid, ids, values, context=context)<br></blockquote><div><br></div><div>hmm -- this is a trick -- in those cases, I find myself using *args, **kwargs when overloading methods. But that does hide the method signature, which is really unfortunate. IT works pretty well for things like GUI toolkits, where you might be subclassing a wx.Window, and the docs for wx.Window are pretty easy to find, but for you own custom classes with nested subclassing, it does get tricky.</div><div><br></div><div>For this case, I kinda like Steve Barnes idea (I think it is his) to have a "magic object of some type, so you can have BOTH specified parameters, and easy access to the *args, **kwargs objects. Though I'm also wary of the magic...</div><div><br></div><div>Perhaps there's some way to make it explicit, like "self":</div><div><br></div><div><font face="monospace, monospace">def fun(a, b, c, d=something, e=something, &args, &&kwargs):</font></div><div><br></div><div>(I'm not sure I like the &, so think of it as a placeholder)</div><div><br></div><div>In this case, then &args would be the *args tuple, and &&kwargs would be the **kwargs dict (as passed in) -- completely redundant with the position and keyword parameters. So the above could be:</div><div><br></div><div><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">def a_method(self, cr, uid, ids, values, context=None, &args, &&kwargs):</span><br style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">    super(self, parent).a_method(*args, **kwargs)</span><br></font></div><div><font face="monospace, monospace"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">    do_things_with(cr, uid, ...)</span><br style="text-decoration-style:initial;text-decoration-color:initial"><br></span></font></div><div>So you now have a clear function signature, access to the parameters, and also a clear an easy way to pass the whole batch on to the superclass' method.</div><div><br></div><div>I just came up with this off teh top of my head, so Im sure there are big issues, but maybe it can steer us in a useful direction.<br><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">-CHB</span><br></div><div><font face="monospace, monospace"><br></font></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div></div><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>