title: Is self.__dict__.update(**kwargs) good or poor style?
body: <p>In Python, say I have some class, Circle, that inherits from Shape. Shape needs x- and y-coordinates, and, in addition, Circle needs a radius. I want to be able to initialize Circle by doing something like,</p>
  
  <pre><code>c = Circle(x=1., y=5., r=3.)
  </code></pre>
  
  <p>Circle inherits from shape, so I need to use named arguments to <code>__init__</code>, because different classes require different constructors. I could manually set x, y, and r.</p>
  
  <pre><code>class Shape(object):
      def __init__(self, **kwargs):
          self.x = kwargs['x']
          self.y = kwargs['y']
  
  class Circle(Shape):
      def __init__(self, **kwargs):
          super(Circle, self).__init__(**kwargs)
          self.r = kwargs['r']
  </code></pre>
  
  <p>or, I could have the attributes of my Circle set automatically using <code>self.__dict__.update(kwargs)</code></p>
  
  <pre><code>class Shape(object):
      def __init__(self, **kwargs):
          self.__dict__.update(**kwargs)
  
  class Circle(Shape):
      def __init__(self, **kwargs):
          super(Circle, self).__init__(**kwargs)
  </code></pre>
  
  <p>The advantage of this is that there's less code and I don't need to maintain boilerplate like <code>self.foo = kwargs['foo']</code>. The disadvantage is that it isn't obvious which arguments are needed for Circle. Is this considered a cheat or is this good style (as long as the interface to Circle is well-documented)?</p>
  
  <hr>
  
  <p>Thanks, everyone, for your thoughtful responses. The <code>self.__dict__.update(**kwargs)</code> hack has been useful for me in experimenting with organizing my code, but I'll make sure that I replace that with properly passing arguments explicitly and doing clear error checking in production code.</p>