Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7424

Re: __doc__ immutable for classes

From Terry Reedy <tjreedy@udel.edu>
Subject Re: __doc__ immutable for classes
Date 2011-06-10 21:17 -0400
References <mailman.65.1307662177.11593.python-list@python.org> <95dvi9Fq9nU1@mid.individual.net>
Newsgroups comp.lang.python
Message-ID <mailman.119.1307755044.11593.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

__doc__ immutable for classes (was: Re: how to inherit docstrings?) Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-09 17:29 -0600
  Re: __doc__ immutable for classes (was: Re: how to inherit docstrings?) Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-10 19:31 +1200
    Re: __doc__ immutable for classes Terry Reedy <tjreedy@udel.edu> - 2011-06-10 21:17 -0400

csiph-web