[Python-checkins] peps: Changed the name mangling from __doc__<attr>__ to __doc_<attr>__ and

georg.brandl python-checkins at python.org
Wed Mar 23 21:27:36 CET 2011


http://hg.python.org/peps/rev/2be804940316
changeset:   166:2be804940316
user:        Marc-André Lemburg <mal at egenix.com>
date:        Wed Aug 30 09:08:16 2000 +0000
summary:
  Changed the name mangling from __doc__<attr>__ to __doc_<attr>__ and
added comments about possible problems.

files:
  pep-0224.txt |  39 ++++++++++++++++++++++++++++++++++-----
  1 files changed, 34 insertions(+), 5 deletions(-)


diff --git a/pep-0224.txt b/pep-0224.txt
--- a/pep-0224.txt
+++ b/pep-0224.txt
@@ -84,7 +84,7 @@
 
     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 @@
     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 @@
     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

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list