title: Python. Is the docstring writable? It seems to be
body: <p><strong>TL;DR</strong> Is a docstring <em>supposed</em> to be writable as simply as </p>
  
  <pre><code>x.__doc__ = 'string' ?
  </code></pre>
  
  <p>It seems to work in 3.5.2.</p>
  
  <p>I've written function for taking and checking GUI keyboard inputs. It's <a href="https://codereview.stackexchange.com/questions/52397/a-general-purpose-gui-data-input-with-validation-but-unclear-about-best-object">here</a> on Code Review if anybody needs the details.</p>
  
  <p>A fundamental part of it is the ability for it to use supplied checking functions, to check whether the input strings are valid in any given context. For better or worse, I decided to use the check function docstring to supply help information to the GUI, which would then parse it, as it was easy to do.</p>
  
  <p>This is an example, the 'pair of floats' check function, the encoding of the help hints into the docstring is fairly obvious.</p>
  
  <pre><code>def float_pair(in_str):
      """[f,f] Two floats separated by a comma
      [end_help]
      in_str     input string which should represent float, float
      raise      ValueError if that's not true
      return     a list of the two values
      """
      fields = in_str.split(',')
      if len(fields) != 2:
          raise ValueError('need two floats separated by one comma')
      output = [float(f) for f in fields]  
      return output
  </code></pre>
  
  <p>I now want to add a capability to check whether a float is in a certain range, ideally passing that range to a check function factory. Ideally the docstring of the returned function will contain the range, so that the help the GUI gives is relevant. I therefore need to set the docstring at run time.</p>
  
  <p>A lot of searching has left me confused about whether a docstring is supposed to be writable or not. I've seen <a href="https://stackoverflow.com/questions/38600186/python-inheriting-docstring-errors-read-only">this</a> question. Unfortunately, I'm only a physicist turned programmer, not a skilled metaprogrammer, so I don't understand the finer points. </p>
  
  <p>So I tried it in the simplest possible way, and it seems to work, at least on python 3.5.2. I'm going to up-version eventually, if for no more than f strings. My concern is whether it's intended to keep working in future releases, or whether it will be 'fixed' to readonly.</p>
  
  <pre><code>def float_range_factory(x, y):
      def float_range(z):
          fz = float(z)
          if x&lt;=fz&lt;y:
              return fz
          raise ValueError('input {} must be in the interval [{}, {}]'.format(z, x, y))
      float_range.__doc__ = '[f range] Return float in the interval [{}, {}]'.format(x, y)
      return float_range
  </code></pre>