[Python-checkins] cpython: Update What's new for PEP 3155

antoine.pitrou python-checkins at python.org
Fri Nov 25 19:15:05 CET 2011


http://hg.python.org/cpython/rev/064f8881eec7
changeset:   73739:064f8881eec7
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Fri Nov 25 19:10:05 2011 +0100
summary:
  Update What's new for PEP 3155

files:
  Doc/whatsnew/3.3.rst |  59 ++++++++++++++++++++++++++++++++
  1 files changed, 59 insertions(+), 0 deletions(-)


diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst
--- a/Doc/whatsnew/3.3.rst
+++ b/Doc/whatsnew/3.3.rst
@@ -189,6 +189,65 @@
         print("You are not allowed to read document.txt")
 
 
+PEP 3155: Qualified name for classes and functions
+==================================================
+
+:pep:`3155` - Qualified name for classes and functions
+ PEP written and implemented by Antoine Pitrou.
+
+Functions and class objects have a new ``__qualname__`` attribute representing
+the "path" from the module top-level to their definition.  For global functions
+and classes, this is the same as ``__name__``.  For other functions and classes,
+it provides better information about where they were actually defined, and
+how they might be accessible from the global scope.
+
+Example with (non-bound) methods::
+
+   >>> class C:
+   ...     def meth(self):
+   ...         pass
+   >>> C.meth.__name__
+   'meth'
+   >>> C.meth.__qualname__
+   'C.meth'
+
+Example with nested classes::
+
+   >>> class C:
+   ...     class D:
+   ...         def meth(self):
+   ...             pass
+   ...
+   >>> C.D.__name__
+   'D'
+   >>> C.D.__qualname__
+   'C.D'
+   >>> C.D.meth.__name__
+   'meth'
+   >>> C.D.meth.__qualname__
+   'C.D.meth'
+
+Example with nested functions::
+
+   >>> def outer():
+   ...     def inner():
+   ...         pass
+   ...     return inner
+   ...
+   >>> outer().__name__
+   'inner'
+   >>> outer().__qualname__
+   'outer.<locals>.inner'
+
+The string representation of those objects is also changed to included the
+new, more precise information::
+
+   >>> str(C.D)
+   "<class '__main__.C.D'>"
+   >>> str(C.D.meth)
+   '<function C.D.meth at 0x7f46b9fe31e0>'
+
+
 Other Language Changes
 ======================
 

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


More information about the Python-checkins mailing list