What is the semantics meaning of 'object'?

Ian Kelly ian.g.kelly at gmail.com
Tue Jun 25 18:25:51 EDT 2013


On Tue, Jun 25, 2013 at 4:17 PM, Chris Angelico <rosuav at 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.

And even if there were, this would be an excellent way to hide bugs.



More information about the Python-list mailing list