[PEP 224] Attribute Docstrings

M.-A. Lemburg mal at lemburg.com
Mon Aug 28 07:54:22 EDT 2000


Warren Focke wrote:
> 
> Marc-Andre Lemburg:
> >     This can lead to cases where the docstring and assignment may be
> >     separated by other expressions:
> >
> >         class C:
> >             "C doc string"
> >
> >             b = 2
> >
> >             def x(self):
> >                 "C.x doc string"
> >                 y = 3
> >                 return 1
> >
> >             "b's doc string"
> >
> >     Since the definition of method "x" currently does not reset the
> >     used assignment name variable, it is still valid when the compiler
> >     reaches the docstring "b's doc string" and thus assigns the string
> >     to __doc__b__.
> >
> >     A possible solution to this problem would be resetting the name
> >     variable for all non-expression nodes.
> 
> So under the "possible solution", the above code would produce
> 
> C.x.__doc__ == "C.x doc string"
> C.__doc__x__ == "b's doc string"
> 
> and C.x would then have two doc strings?

No, resetting the variable would cause it to be NULL at the
time the compiler reaches "b's doc string" and this would
cause the docstring to be ignored.

> Would it be reasonable to only
> reset the variable if x didn't have a .__doc__?

Hmm, that would be an idea... I'll think about it.

Thanks,
-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/




More information about the Python-list mailing list