When is __getattribute__ not involved in attribute searches?

Consider the following:

class A(object):
    def __init__(self):
        print 'Hello!'

    def foo(self):
        print 'Foo!'

    def __getattribute__(self, att):
        raise AttributeError()

a = A() # Works, prints "Hello!"
a.foo() # throws AttributeError as expected

The implementation __getattribute__, obviously, does not perform all searches. My questions:

  • Why is it still possible to instantiate an object? I would expect the search for the method itself to __init__also fail.
  • What is a list of attributes that do not fall under __getattribute__?
+4
source share
1 answer

The implementation __getattribute__obviously does not allow all requests to be executed

Let's say this is not suitable for all vanilla searches.

So, how was it __getattribute__called first, since it is also an attribute of the class?


, . , , __getattribute__ ( ).

, __init__, ( ), .

?

:

a = A()

__init__ , . . , __setattr__, __delattr__, __getattribute__ .

__init__:

a.__init__()

. Eh, , .

, __getattribute__ :

a.__getattribute__

AttributeError; __getattribute__, .


, __getattribute__?

__getattribute__ , . , __getattribute__ .

+2

All Articles