[Python-ideas] Override dict.__new__ to raise if cls is not dict; do the same for str, list, etc.

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Apr 22 01:39:16 EDT 2016


Random832 wrote:
> If a class defines __slots__, the *instances* don't have a __dict__, but
> the *class* sure as hell still does. Even, as it turns out, if the
> metaclass had __slots__. (Not sure what's up with that, actually).

It's because metaclasses are all based on type, whose instances
have a dict. An object will always have a dict if any of its base
classes cause it to have a dict.

-- 
Greg


More information about the Python-ideas mailing list