Say I have this sample code I'm writing for a Python lesson I'm holding:
class Enum(dict):
def __init__(self, *values):
values = {mnemo: num
for num, mnemo in enumerate(values)}
dict.__init__(self, values) # ← this
def __getattr__(self, name):
return self[name]
This seems to work as expected, at least on a shallow method, but what I see most of the time on the literature on the Internet is:
- Avoid inheriting from inbuilt types: it's much better to type out proxy methods by hand!
- Using
super().method
rather than explicitly namingsuperclass.method
I guess especially the latter is more DRY, but super() is going to be trickier to explain once I start throwing in multiple inheritance. I want to make sure, then, that there are no nasty gotchas in there that other people will then stumble upon.