Subclassing built-in types in Python is pretty straightforward. A built-in type, called object is a common ancestor for all built-in types, as well as for all user-defined classes that have no explicit parent class specified. Thanks to this, every time you need to implement a class that behaves almost like one of the built-in types, the best practice is to subtype it.
Now, we will look at the code for a class called distinctdict, which uses this technique. It will be a subclass of the usual Python dict type. This new class will behave, in most ways, like an ordinary Python dict type. But, instead of allowing multiple keys with the same value, when someone tries to add a new entry with an identical value, it raises a ValueError subclass with a help message.
As already stated, the built-in dict type is an object subclass:
>>> isinstance(dict(...