title: Where to put the separation between a stateful object and a stateless calculation in Python?
body: <p>Which of the following code snippets is the most "pythonic"? The calculation is trivial in this example but could be assumed to be complex in real life.</p>
  
  <pre><code>class A(object):
      """Freely mix state and calcs - no good I presume"""
      def __init__(self, state):
          self.state = state
  
      def calc_with_state(self, x):
          return (self.state + x)**2
  </code></pre>
  
  <p>or</p>
  
  <pre><code>class B(object):
      """Separate state from calc by a static method"""
      @staticmethod
      def inner_calc(u, v):
          return (u + v)**2
  
      def __init__(self, state):
          self.state = state
  
      def calc_with_state(self, x):
          return B.inner_calc(self.state, x)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>class C(object):
      """Break out the calculation in a free function"""
      def __init__(self, state):
          self.state = state
  
      def calc_with_state(self, x):
          return outer_calc(self.state, x)
  
  def outer_calc(u, v):
      return (u + v)**2
  </code></pre>