Changed the name mangling from __doc__<attr>__ to __doc_<attr>__ and

added comments about possible problems.
This commit is contained in:
Marc-André Lemburg 2000-08-30 09:08:16 +00:00
parent ec2992742f
commit c0b08ef899
1 changed files with 34 additions and 5 deletions

View File

@ -84,7 +84,7 @@ Implementation
The following name mangling scheme achieves all of the above:
__doc__<attributename>__
__doc_<attributename>__
To keep track of the last assigned name, the byte code compiler
stores this name in a variable of the compiling structure. This
@ -102,8 +102,8 @@ Implementation
In the above example this would result in the following new class
attributes to be created:
C.__doc__a__ == "attribute C.a doc-string (1)"
C.__doc__b__ == "attribute C.b doc-string (2)"
C.__doc_a__ == "attribute C.a doc-string (1)"
C.__doc_b__ == "attribute C.b doc-string (2)"
A patch to the current CVS version of Python 2.0 which implements
the above is available on SourceForge at [1].
@ -134,10 +134,39 @@ Caveats of the Implementation
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__.
to __doc_b__.
A possible solution to this problem would be resetting the name
variable for all non-expression nodes.
variable for all non-expression nodes in the compiler.
Possible Problems
Even though highly unlikely, attribute docstrings could get
accidentally concatenated to the attribute's value:
class C:
x = "text" \
"x's docstring"
The trailing slash would cause the Python compiler to concatenate
the attribute value and the docstring.
A modern syntax highlighting editor would easily make this
accident visible, though, and by simply inserting emtpy lines
between the attribute definition and the docstring you can avoid
the possible concatenation completely, so the problem is
negligible.
Another possible problem is that of using triple quoted strings as
a way to uncomment parts of your code.
If there happens to be an assignment just before the start of the
comment string, then the compiler will treat the comment as
docstring attribute and apply the above logic to it.
Besides generating a docstring for an otherwise undocumented
attribute there is no breakage.
Copyright