__doc__ immutable for classes

Terry Reedy tjreedy at udel.edu
Fri Jun 10 21:17:09 EDT 2011


On 6/10/2011 3:31 AM, Gregory Ewing wrote:
> Eric Snow wrote:
>> But for "method" objects (really a wrapper for
>> bound functions) would it change the __doc__ of the wrapper or of the
>> bound function?
>
> You probably wouldn't want to change the __doc__ of a method
> wrapper; instead you'd make sure you got hold of the underlying
> function first. So __doc__ on method wrappers should probably
> remain read-only to avoid surprises.

In 3.x there are no general method wrappers; only bound methods. The 
.__doc__ attribute of bound methods equals and I am very sure *is* the 
doc string of the underlying function, accessed through a custom 
method.__getattr__. It is not writable through the bound method. I 
presume this is because method.__setattr__ blocks the write. Directly 
binding a new string to the underlying function does work.

-- 
Terry Jan Reedy




More information about the Python-list mailing list