On Wed, Jun 26, 2013 at 8:25 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Tue, Jun 25, 2013 at 4:17 PM, Chris Angelico <ros...@gmail.com> wrote: >> The main problem is getting to the top/end of the call chain. Classic >> example is with __init__, but the same problem can also happen with >> other calls. Just a crazy theory, but would it be possible to >> construct a black-holing object that, for any given method name, >> returns a dummy function that ignores its args? (Other forms of >> attribute lookup aren't going to be a problem, I think, so this can be >> just methods/functions.) Then you just subclass from that all the >> time, instead of from object itself, and you should be able to safely >> call super's methods with whatever kwargs you haven't yourself >> processed. Would that work? > > class BlackHole(object): > def __getattr__(self, attr): > return lambda *args, **kwargs: None > > There's no way to restrict it to just methods, because there's no > fundamental difference in Python between methods and other attributes, > and at the point that you're looking it up you have no way of knowing > whether the result is about to be called or not.
Right, but what I mean is that you don't need any sort of special-casing to pick an object type to return. Just return a function, because that's going to be safe. > And even if there were, this would be an excellent way to hide bugs. Ehh, true. Don't know a way around that one. Meh. ChrisA -- http://mail.python.org/mailman/listinfo/python-list