Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Below is an example of shadowing a parent method in a child class.

Animal

<__main__.Animal at 0x7f58845dc4f0>
['get_name', 'name', 'sound']
'whoever'

Dog

Verify that dir(dog) does not show the shadowed method get_name.

['name', 'sleep', 'sound']

Verify that the method get_name is not accessible via an instance of Dog.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [34], in <cell line: 1>()
----> 1 dog.get_name()

Input In [27], in Dog.__getattribute__(self, name)
     22 def __getattribute__(self, name):
     23     if name in ["get_name"]: 
---> 24         raise AttributeError(name)
     25     else: 
     26         return super().__getattribute__(name)

AttributeError: get_name

Verify that other methods are accessible.

'Bark!'
'Quiet.'

However, notice that even if the shadowed parent method get_name won’t be seen using dir(dog), it still shows up by call dir(Dog).

['get_name', 'sound']

References

https://medium.com/maouu/sorry-but-youre-wrong-aea1b88ffc03