do not subclass built-in classes in python

Author: yifei / Created: May 30, 2017, 9:17 p.m. / Modified: May 30, 2017, 9:19 p.m. / Edit

In short, they will not behave what you think they will. you think dict.get in implemented in python, like:

def get(self, key, default=None):
        return self[key]
    except KeyError:
        return default

However, they dict.get do not call __getitem__, and they are implemented in c separately, and do not call each other.

so, when you implement __geitem__, get is not automatically altered! which is very dangerous.

What you need do, subclass