summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-25 18:10:05 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-25 18:10:05 (GMT)
commit6bbd76b0a0bb1b98e310b187f82aa2b93eb6ac29 (patch)
tree60cadd9e152c6242a5f8e2bc911279dc570bec13 /Doc/whatsnew
parent86a36b500a7f7581194382ce4df914e4bb487873 (diff)
downloadcpython-6bbd76b0a0bb1b98e310b187f82aa2b93eb6ac29.zip
cpython-6bbd76b0a0bb1b98e310b187f82aa2b93eb6ac29.tar.gz
cpython-6bbd76b0a0bb1b98e310b187f82aa2b93eb6ac29.tar.bz2
Update What's new for PEP 3155
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r--Doc/whatsnew/3.3.rst59
1 files changed, 59 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst
index 0c3be15..6c20418 100644
--- a/Doc/whatsnew/3.3.rst
+++ b/Doc/whatsnew/3.3.rst
@@ -189,6 +189,65 @@ inspection of exception attributes::
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
======================