@@ -1986,7 +1986,8 @@ Basic customization
19861986 "informal" string representation of instances of that class is required.
19871987
19881988 This is typically used for debugging, so it is important that the representation
1989- is information-rich and unambiguous.
1989+ is information-rich and unambiguous. A default implementation is provided by the
1990+ :class: `object ` class itself.
19901991
19911992 .. index ::
19921993 single: string; __str__() (object method)
@@ -1996,10 +1997,10 @@ Basic customization
19961997
19971998.. method :: object.__str__(self)
19981999
1999- Called by :func: `str(object) <str> ` and the built-in functions
2000- :func: ` format ` and :func: `print ` to compute the "informal" or nicely
2000+ Called by :func: `str(object) <str> `, the default :meth: ` __format__ ` implementation,
2001+ and the built-in function :func: `print `, to compute the "informal" or nicely
20012002 printable string representation of an object. The return value must be a
2002- :ref: `string <textseq >` object.
2003+ :ref: `str <textseq >` object.
20032004
20042005 This method differs from :meth: `object.__repr__ ` in that there is no
20052006 expectation that :meth: `__str__ ` return a valid Python expression: a more
@@ -2016,7 +2017,8 @@ Basic customization
20162017 .. index :: pair: built-in function; bytes
20172018
20182019 Called by :ref: `bytes <func-bytes >` to compute a byte-string representation
2019- of an object. This should return a :class: `bytes ` object.
2020+ of an object. This should return a :class: `bytes ` object. The :class: `object `
2021+ class itself does not provide this method.
20202022
20212023 .. index ::
20222024 single: string; __format__() (object method)
@@ -2040,6 +2042,9 @@ Basic customization
20402042
20412043 The return value must be a string object.
20422044
2045+ The default implementation by the :class: `object ` class should be given
2046+ an empty *format_spec * string. It delegates to :meth: `__str__ `.
2047+
20432048 .. versionchanged :: 3.4
20442049 The __format__ method of ``object `` itself raises a :exc: `TypeError `
20452050 if passed any non-empty string.
@@ -2082,6 +2087,12 @@ Basic customization
20822087 ``(x<y or x==y) `` does not imply ``x<=y ``. To automatically generate ordering
20832088 operations from a single root operation, see :func: `functools.total_ordering `.
20842089
2090+ By default, the :class: `object ` class provides implementations consistent
2091+ with :ref: `expressions-value-comparisons `: equality compares according to
2092+ object identity, and order comparisons raise :exc: `TypeError `. Each default
2093+ method may generate these results directly, but may also return
2094+ :data: `NotImplemented `.
2095+
20852096 See the paragraph on :meth: `__hash__ ` for
20862097 some important notes on creating :term: `hashable ` objects which support
20872098 custom comparison operations and are usable as dictionary keys.
@@ -2137,9 +2148,9 @@ Basic customization
21372148 bucket).
21382149
21392150 User-defined classes have :meth: `__eq__ ` and :meth: `__hash__ ` methods
2140- by default; with them, all objects compare unequal (except with themselves)
2141- and ``x.__hash__() `` returns an appropriate value such that `` x == y ``
2142- implies both that ``x is y `` and ``hash(x) == hash(y) ``.
2151+ by default (inherited from the :class: ` object ` class) ; with them, all objects compare
2152+ unequal (except with themselves) and ``x.__hash__() `` returns an appropriate
2153+ value such that `` x == y `` implies both that ``x is y `` and ``hash(x) == hash(y) ``.
21432154
21442155 A class that overrides :meth: `__eq__ ` and does not define :meth: `__hash__ `
21452156 will have its :meth: `__hash__ ` implicitly set to ``None ``. When the
@@ -2189,8 +2200,8 @@ Basic customization
21892200 ``bool() ``; should return ``False `` or ``True ``. When this method is not
21902201 defined, :meth: `~object.__len__ ` is called, if it is defined, and the object is
21912202 considered true if its result is nonzero. If a class defines neither
2192- :meth: `!__len__ ` nor :meth: `!__bool__ `, all its instances are considered
2193- true.
2203+ :meth: `!__len__ ` nor :meth: `!__bool__ ` (which is true of the :class: ` object `
2204+ class itself), all its instances are considered true.
21942205
21952206
21962207.. _attribute-access :
@@ -2212,6 +2223,7 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
22122223 for ``self ``; or :meth: `__get__ ` of a *name * property raises
22132224 :exc: `AttributeError `). This method should either return the (computed)
22142225 attribute value or raise an :exc: `AttributeError ` exception.
2226+ The :class: `object ` class itself does not provide this method.
22152227
22162228 Note that if the attribute is found through the normal mechanism,
22172229 :meth: `__getattr__ ` is not called. (This is an intentional asymmetry between
@@ -2350,8 +2362,8 @@ method (a so-called *descriptor* class) appears in an *owner* class (the
23502362descriptor must be in either the owner's class dictionary or in the class
23512363dictionary for one of its parents). In the examples below, "the attribute"
23522364refers to the attribute whose name is the key of the property in the owner
2353- class' :attr: `~object.__dict__ `.
2354-
2365+ class' :attr: `~object.__dict__ `. The :class: ` object ` class itself does not
2366+ implement any of these protocols.
23552367
23562368.. method :: object.__get__(self, instance, owner=None)
23572369
@@ -3043,17 +3055,19 @@ Emulating callable objects
30433055
30443056 Called when the instance is "called" as a function; if this method is defined,
30453057 ``x(arg1, arg2, ...) `` roughly translates to ``type(x).__call__(x, arg1, ...) ``.
3058+ The :class: `object ` class itself does not provide this method.
30463059
30473060
30483061.. _sequence-types :
30493062
30503063Emulating container types
30513064-------------------------
30523065
3053- The following methods can be defined to implement container objects. Containers
3054- usually are :term: `sequences <sequence> ` (such as :class: `lists <list> ` or
3066+ The following methods can be defined to implement container objects. None of them
3067+ are provided by the :class: `object ` class itself. Containers usually are
3068+ :term: `sequences <sequence> ` (such as :class: `lists <list> ` or
30553069:class: `tuples <tuple> `) or :term: `mappings <mapping> ` (like
3056- :class : `dictionaries <dict > `),
3070+ :term : `dictionaries <dictionary > `),
30573071but can represent other containers as well. The first set of methods is used
30583072either to emulate a sequence or to emulate a mapping; the difference is that for
30593073a sequence, the allowable keys should be the integers *k * for which ``0 <= k <
@@ -3416,6 +3430,7 @@ Typical uses of context managers include saving and restoring various kinds of
34163430global state, locking and unlocking resources, closing opened files, etc.
34173431
34183432For more information on context managers, see :ref: `typecontextmanager `.
3433+ The :class: `object ` class itself does not provide the context manager methods.
34193434
34203435
34213436.. method :: object.__enter__(self)
@@ -3620,6 +3635,8 @@ are awaitable.
36203635 Must return an :term: `iterator `. Should be used to implement
36213636 :term: `awaitable ` objects. For instance, :class: `asyncio.Future ` implements
36223637 this method to be compatible with the :keyword: `await ` expression.
3638+ The :class: `object ` class itself is not awaitable and does not provide
3639+ this method.
36233640
36243641 .. note ::
36253642
@@ -3705,6 +3722,9 @@ its ``__anext__`` method.
37053722
37063723Asynchronous iterators can be used in an :keyword: `async for ` statement.
37073724
3725+ The :class: `object ` class itself does not provide these methods.
3726+
3727+
37083728.. method :: object.__aiter__(self)
37093729
37103730 Must return an *asynchronous iterator * object.
@@ -3751,6 +3771,8 @@ suspend execution in its ``__aenter__`` and ``__aexit__`` methods.
37513771
37523772Asynchronous context managers can be used in an :keyword: `async with ` statement.
37533773
3774+ The :class: `object ` class itself does not provide these methods.
3775+
37543776.. method :: object.__aenter__(self)
37553777
37563778 Semantically similar to :meth: `~object.__enter__ `, the only
0 commit comments