title: Good semantics, Subclass or emulate?
body: <p>I have been using python for a while now and Im happy using it in most forms but I am wondering which form is more pythonic. Is it right to emulate objects and types or is it better to subclass or inherit from these types. I can see advantages for both and also the disadvantages. Whats the correct method to be doing this?</p>
  
  <p>Subclassing method</p>
  
  <pre><code>class UniqueDict(dict):
      def __init__(self, *args, **kwargs):
          dict.__init__(self, *args, **kwargs)
  
      def __setitem__(self, key, value):
          if key not in self:
              dict.__setitem__(self, key, value)
          else:
              raise KeyError("Key already exists")
  </code></pre>
  
  <p>Emulating method</p>
  
  <pre><code>class UniqueDict(object):
      def __init__(self, *args, **kwargs):
          self.di = dict(*args, **kwargs)
  
      def __setitem__(self, key, value):
          if key not in self.di:
              self.di[key] = value
          else:
              raise KeyError("Key already exists")
  </code></pre>