(original) (raw)
changeset: 89392:4cd620d8c3f6 user: R David Murray rdmurray@bitdance.com date: Tue Feb 25 16:03:14 2014 -0500 files: Doc/library/types.rst Doc/whatsnew/3.4.rst description: 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. diff -r 489150765b58 -r 4cd620d8c3f6 Doc/library/types.rst --- a/Doc/library/types.rst Tue Feb 25 14:36:20 2014 -0500 +++ b/Doc/library/types.rst Tue Feb 25 16:03:14 2014 -0500 @@ -15,6 +15,9 @@ 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 @@ 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 @@ 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 -r 489150765b58 -r 4cd620d8c3f6 Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst Tue Feb 25 14:36:20 2014 -0500 +++ b/Doc/whatsnew/3.4.rst Tue Feb 25 16:03:14 2014 -0500 @@ -1270,6 +1270,17 @@ :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 @@ 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: /rdmurray@bitdance.com