title: Implementing a dict-like object with __getattr__ and __setattr__ functionality
body: <p>I'm trying to implement a <code>dict</code>-like object which can be accessed/modified with <code>__getattr__</code> and <code>__setattr__</code> for ease of use for my users. The class also implements some other simple functionality.</p>
  
  <p>Using <a href="https://stackoverflow.com/questions/3387691/how-to-perfectly-override-a-dict/3387975#3387975">this answer</a> as a template, my implementation is currently as follows:</p>
  
  <pre><code>from collections import MutableMapping
  
  class Dictish (MutableMapping):
      """
      A dict-like mapping object. vals are always coerced to str.
      Should provide __getattr__ and __setattr__ as aliases for
      __getitem__ and __setitem__.
      """
      def __init__ ( self, *args, **kwargs ):
          self.store = dict()
          self.update(dict(*args,**kwargs))
  
      def __getitem__ ( self, key : str ) -&gt; str:
          return self.store[key]
  
      def __setitem__ ( self, key : str, val : str ) -&gt; None:
          self.store[key] = str(val)
  
      def __delitem__ ( self, key : str ) -&gt; None:
          del self.store[key]
  
      def __iter__ ( self ):
          return iter(self.store)
  
      def __len__ ( self ) -&gt; int:
          return len(self.store)
  
      def __repr__ ( self ) -&gt; str:
          return repr(self.store)
  
      # works fine by itself, but goes into infinite recursion
      # when __setattr__ is defined
      def __getattr__ ( self, attr : str ) -&gt; str:
          return self.__getitem__(attr)
  
  #    def __setattr__ ( self, attr : str, val : str ) -&gt; None:
  #        self.__setitem__(attr,val)
  </code></pre>