On Mon, Sep 10, 2018 at 11:00 PM, Ethan Furman <et...@stoneleaf.us> wrote:
> > 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: > > def a_method(self, cr, uid, ids, values, context=None): > ... > super(self, parent).a_method(cr, uid, ids, values, context=context) > 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. 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... Perhaps there's some way to make it explicit, like "self": def fun(a, b, c, d=something, e=something, &args, &&kwargs): (I'm not sure I like the &, so think of it as a placeholder) 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: def a_method(self, cr, uid, ids, values, context=None, &args, &&kwargs): super(self, parent).a_method(*args, **kwargs) do_things_with(cr, uid, ...) 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. 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. -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/