diff -r 0d84855861ff Doc/library/functions.rst --- a/Doc/library/functions.rst Sun Jul 06 21:37:15 2014 -0400 +++ b/Doc/library/functions.rst Mon Jul 07 12:46:58 2014 +0200 @@ -1,4 +1,3 @@ -.. XXX document all delegations to __special__ methods .. _built-in-funcs: Built-in Functions @@ -270,6 +269,8 @@ function deletes the named attribute, provided the object allows it. For example, ``delattr(x, 'foobar')`` is equivalent to ``del x.foobar``. + Attribute deletion can be customized by implementing :meth:`__delattr__`. + .. _func-dict: .. function:: dict(**kwarg) @@ -571,6 +572,9 @@ ``x.foobar``. If the named attribute does not exist, *default* is returned if provided, otherwise :exc:`AttributeError` is raised. + Attribute access can be customized by implementing :meth:`__getattr__` and/or + :meth:`__getattribute__`. + .. function:: globals() @@ -582,9 +586,11 @@ .. function:: hasattr(object, name) The arguments are an object and a string. The result is ``True`` if the - string is the name of one of the object's attributes, ``False`` if not. (This + string is the name of one of the object's attributes, ``False`` if not. This is implemented by calling ``getattr(object, name)`` and seeing whether it - raises an :exc:`AttributeError` or not.) + raises an :exc:`AttributeError` or not. As a result, the effects of any + implemented :meth:`__getattr__` or :meth:`__getattribute__` are considered + for the result of this function. .. function:: hash(object) @@ -746,6 +752,9 @@ sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set). + Determining the length of an object may be customized by implementing + :meth:`__len__`. + .. _func-list: .. function:: list([iterable]) @@ -1242,6 +1251,8 @@ object allows it. For example, ``setattr(x, 'foobar', 123)`` is equivalent to ``x.foobar = 123``. + Attribute assignment can be customized by implementing :meth:`__setattr__`. + .. function:: slice(stop) slice(start, stop[, step]) @@ -1275,9 +1286,16 @@ Use :func:`functools.cmp_to_key` to convert an old-style *cmp* function to a *key* function. + The items in *iterable* need to be orderable; otherwise, :exc:`TypeError` is + raised. Type :class:`object` is not orderable; classes can become orderable + by defining :dfn:`rich comparison methods` like :meth:`__lt__`, described in + section :ref:`customization`. For details on the orderability of built-in + types, see :ref:`comparisons`. + For sorting examples and a brief sorting tutorial, see `Sorting HowTo `_\. + .. function:: staticmethod(function) Return a static method for *function*.