So, I agree. Let's not enforce type safety in Python, but I would like to protect myself from silly mistakes. So what do we think about this?
class Animal(object):
values = ['Horse','Dog','Cat']
class __metaclass__(type):
def __getattr__(self, name):
return self.values.index(name)
It keeps me from value-collision in defining my enums.
>>> Animal.Cat
2
There's another handy advantage: really fast reverse lookups:
def name_of(self, i):
return self.values[i]