From: Antoine Pitrou Date: Fri, 25 Nov 2011 18:10:05 +0000 (+0100) Subject: Update What's new for PEP 3155 X-Git-Tag: v3.3.0a1~732^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6bbd76b0a0bb1b98e310b187f82aa2b93eb6ac29;p=python Update What's new for PEP 3155 --- diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index 0c3be15627..6c2041840a 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..inner' + +The string representation of those objects is also changed to included the +new, more precise information:: + + >>> str(C.D) + "" + >>> str(C.D.meth) + '' + + Other Language Changes ======================