Modifying built-in function
Question: Let's consider any user-defined pythonic class. If I call
`dir(obect_of_class)`, I get the list of its attributes:

    
    
    ['__class__', '__delattr__', '__dict__', '__dir__', ... '__weakref__', 'bases', 
    'build_full_name', 'candidates', ... 'update_name'].
    

You can see 2 types of attributes in this list:

  * built-in attributes, 
  * user defined.

I need to override `__dir__` so, that it will return only user defined
attribltes. How I can do that?

It is clear, that if in overridden function I call itself, it gives me
infinite recursion. So, I want to do somethig like this:

    
    
    def __dir__(self):
            return list(filter(lambda x: not re.match('__\S*__', x), dir(self)))
    

but evade the infinite recursion.

In general, how can I modify a built-in function if I don't want to write it
from scratch but want to modify the existing function?


Answer: Use [`super`](https://docs.python.org/3/library/functions.html#super) to call
parent's implementation of `__dir__`; avoid the recursion:

    
    
    import re
    
    
    class AClass:
    
        def __dir__(self):
            return [x for x in super().__dir__() if not re.match(r'__\S+__$', x)]
    
        def method(self):
            pass
    

* * *
    
    
    >>> dir(AClass())
    ['method']
    

