How does getattribute with set descriptor work?

So, here you are asking why we don’t see the __getattribute__ getting called twice, once for each attribute assignment: name, and desc. Well, that is because the __getattribute__ is not designed to get called during attribute initial assignments (when they’re first created). It wouldn’t make much sense since you would expect it to be called during an actual event in your code or process and NOT during its initial design phase.

Note that for the desc attribute, it is fetched, as per my previous post during this line of code AFTER having already been initialized (conversely, you can comment this line out to confirm that it is not the assignment that induces the __getattribute__ method to be called):

instance.__dict__[self.private_name] = new_value

So, any fetch after the initial assignment, is fair game. If you add the following two print statements to the constructor, fetching the two attributes, you will notice that the __getattribute__ does get called twice as per your concern.

    def __init__(self, name, desc):
        print('Inside __init__ constructor.')
        self.name = name
        self.desc = desc
        print(self.name)   # fetch attribute - induces __getattribute__ call
        print(self.desc)    # fetch attribute - induces __getattribute__ call

Modify the test code that I previously provided to have these two additional lines and observe the results.

Here is the code trajectory from the previous code that I provided: