From 13cc883aaa69b61416c5f7c3f216d258d46040d9 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Tue, 25 Feb 2014 16:03:14 -0500 Subject: [PATCH] whatsnew: DynanicClassAttribute (#19030), Py_SetStandardStreamEncoding (#16129) Adding missing docs for DynamicClassAttribute by copying the docstring. The doc entry could stand some expansion, which I will note on the issue. --- Doc/library/types.rst | 21 +++++++++++++++++++++ Doc/whatsnew/3.4.rst | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Doc/library/types.rst b/Doc/library/types.rst index c4f57e43af..abdb939d1a 100644 --- a/Doc/library/types.rst +++ b/Doc/library/types.rst @@ -15,6 +15,9 @@ It also defines names for some object types that are used by the standard Python interpreter, but not exposed as builtins like :class:`int` or :class:`str` are. +Finally, it provides some additional type-related utility classes and functions +that are not fundamental enough to be builtins. + Dynamic Type Creation --------------------- @@ -220,6 +223,9 @@ Standard names are defined for the following types: Return a new view of the underlying mapping's values. +Additional Utility Classes and Functions +---------------------------------------- + .. class:: SimpleNamespace A simple :class:`object` subclass that provides attribute access to its @@ -246,3 +252,18 @@ Standard names are defined for the following types: instead. .. versionadded:: 3.3 + + +.. function:: DynamicClassAttribute(fget=None, fset=None, fdel=None, doc=None) + + Route attribute access on a class to __getattr__. + + This is a descriptor, used to define attributes that act differently when + accessed through an instance and through a class. Instance access remains + normal, but access to an attribute through a class will be routed to the + class's __getattr__ method; this is done by raising AttributeError. + + This allows one to have properties active on an instance, and have virtual + attributes on the class with the same name (see Enum for an example). + + .. versionadded:: 3.4 diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst index 109549e071..78fa24b4f2 100644 --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1270,6 +1270,17 @@ reducing the amount of memory consumed. (Contributed by Andrew Kuchling in :issue:`1565525`). +types +----- + +A new :func:`~types.DynamicClassAttribute` descriptor provides a way to define +an attribute that acts normally when looked up through an instance object, but +which is routed to the *class* ``__getattr__`` when looked up through the +class. This allows one to have properties active on a class, and have virtual +attributes on the class with the same name (see :mod:`Enum` for an example). +(Contributed by Ethan Furman in :issue:`19030`.) + + urllib ------ @@ -1512,6 +1523,12 @@ Other Build and C API Changes object allocator have been silenced. (Contributed by Dhiru Kholia in :issue:`18596`.) +* New function :c:func:`Py_SetStandardStreamEncoding` allows an application + that is embedding Python to do the equivalent of setting + :envvar:`PYTHONIOENCODING`. Its arguments override the equivalent + values from :envvar:`PYTHONIOENCODING` if it exists. (Contributed + by Bastien Montagne and Nick Coghlan in :issue:`16129`.) + .. _other-improvements-3.4: -- 2.40.0