always call the base class method with the same name to access any attributes it needs, for example,$_{object.}$ __getattribute__(self, name) . Note: This method may still be bypassed when looking up special methods as the result of implicit invocation via language syntax or built-in functions. See Special method lookup . For certain sensitive attribute accesses, raises an auditing event object.__getattr__ with arguments $_{obj}$and$_{name}$ . If$_{__setattr__()}$ wants to assign to an instance attribute, it should call the base class method with the same name, for example, object.__setattr__(self, name, value) . For certain sensitive attribute assignments, raises an auditing event$_{object.__setattr__}$ with arguments $_{obj}$,$_{name}$ ,$_{value}$ . For certain sensitive attribute deletions, raises an auditing event$_{object.__delattr__}$ with arguments $_{obj}$and$_{name}$ . Special names __getattr__ and __dir__ can be also used to customize access to module attributes. The __getattr__ function at the module level should accept one argument which is the name of an attribute and return the computed value or raise an$_{AttributeError}$. If an attribute is not found on a module object through the nor- mal lookup, i.e.$_{object.__getattribute__()}$ , then$_{__getattr__}$ is searched in the module$_{__dict__}$ before raising an$_{AttributeError}$. If found, it is called with the attribute name and the result is returned. The$_{__dir__}$ function should accept no arguments, and return a sequence of strings that represents the names accessible on module. If present, this function overrides the standard$_{dir()}$ search on a module. For a more fine grained customization of the module behavior (setting attributes, properties, etc.), one can set the __class__ attribute of a module object to a subclass of$_{types.ModuleType}$ . For example: Note: Defining module __getattr__ and setting module __class__ only affect lookups made using the attribute access syntax – directly accessing the module globals (whether by code within the module, or via a reference to the module’s globals dictionary) is unaffected. Chapter 3. Data model 30 import sys from types import ModuleType classVerboseModule (ModuleType): def __repr__ (self): return f'Verbose { self.__name__ } ' def __setattr__ (self, attr, value): print(f'Setting { attr } ... ') super() .__setattr__ (attr, value) sys.modules[__name__ ].__class__ =VerboseModule Customizing module attribute access object. __dir__ ( self$_{)}$ Called when$_{dir()}$ is called on the object. A sequence must be returned. dir() converts the returned sequence to a list and sorts it. object. __delattr__ ( self , name$_{)}$ Like __setattr__() but for attribute deletion instead of assignment. This should only be implemented if del obj.name is meaningful for the object. object. __setattr__ ( self , name , value$_{)}$ Called when an attribute assignment is attempted. This is called instead of the normal mechanism (i.e. store the value in the instance dictionary). name is the attribute name, value is the value to be assigned to it. The Python Language Reference, Release 3.9.5