@@ -88,7 +88,7 @@ Some objects contain references to "external" resources such as open files or
88
88
windows. It is understood that these resources are freed when the object is
89
89
garbage-collected, but since garbage collection is not guaranteed to happen,
90
90
such objects also provide an explicit way to release the external resource,
91
- usually a :meth: `close ` method. Programs are strongly recommended to explicitly
91
+ usually a :meth: `! close ` method. Programs are strongly recommended to explicitly
92
92
close such objects. The ':keyword: `try `...\ :keyword: `finally `' statement
93
93
and the ':keyword: `with `' statement provide convenient ways to do this.
94
94
@@ -681,8 +681,8 @@ underlying the class method.
681
681
When an instance method object is called, the underlying function
682
682
(:attr: `__func__ `) is called, inserting the class instance
683
683
(:attr: `__self__ `) in front of the argument list. For instance, when
684
- :class: `C ` is a class which contains a definition for a function
685
- :meth: `f `, and ``x `` is an instance of :class: `C `, calling ``x.f(1) `` is
684
+ :class: `! C ` is a class which contains a definition for a function
685
+ :meth: `! f `, and ``x `` is an instance of :class: `! C `, calling ``x.f(1) `` is
686
686
equivalent to calling ``C.f(x, 1) ``.
687
687
688
688
When an instance method object is derived from a class method object, the
@@ -795,7 +795,7 @@ Classes
795
795
Classes are callable. These objects normally act as factories for new
796
796
instances of themselves, but variations are possible for class types that
797
797
override :meth: `~object.__new__ `. The arguments of the call are passed to
798
- :meth: `__new__ ` and, in the typical case, to :meth: `~object.__init__ ` to
798
+ :meth: `! __new__ ` and, in the typical case, to :meth: `~object.__init__ ` to
799
799
initialize the new instance.
800
800
801
801
@@ -899,9 +899,9 @@ https://www.python.org/download/releases/2.3/mro/.
899
899
pair: object; dictionary
900
900
pair: class; attribute
901
901
902
- When a class attribute reference (for class :class: `C `, say) would yield a
902
+ When a class attribute reference (for class :class: `! C `, say) would yield a
903
903
class method object, it is transformed into an instance method object whose
904
- :attr: `__self__ ` attribute is :class: `C `. When it would yield a static
904
+ :attr: `__self__ ` attribute is :class: `! C `. When it would yield a static
905
905
method object, it is transformed into the object wrapped by the static method
906
906
object. See section :ref: `descriptors ` for another way in which attributes
907
907
retrieved from a class may differ from those actually contained in its
@@ -1898,13 +1898,17 @@ class' :attr:`~object.__dict__`.
1898
1898
1899
1899
Called to delete the attribute on an instance *instance * of the owner class.
1900
1900
1901
+ Instances of descriptors may also have the :attr: `!__objclass__ ` attribute
1902
+ present:
1901
1903
1902
- The attribute :attr: `__objclass__ ` is interpreted by the :mod: `inspect ` module
1903
- as specifying the class where this object was defined (setting this
1904
- appropriately can assist in runtime introspection of dynamic class attributes).
1905
- For callables, it may indicate that an instance of the given type (or a
1906
- subclass) is expected or required as the first positional argument (for example,
1907
- CPython sets this attribute for unbound methods that are implemented in C).
1904
+ .. attribute :: object.__objclass__
1905
+
1906
+ The attribute :attr: `!__objclass__ ` is interpreted by the :mod: `inspect ` module
1907
+ as specifying the class where this object was defined (setting this
1908
+ appropriately can assist in runtime introspection of dynamic class attributes).
1909
+ For callables, it may indicate that an instance of the given type (or a
1910
+ subclass) is expected or required as the first positional argument (for example,
1911
+ CPython sets this attribute for unbound methods that are implemented in C).
1908
1912
1909
1913
1910
1914
.. _descriptor-invocation :
@@ -1985,13 +1989,14 @@ For instance bindings, the precedence of descriptor invocation depends on
1985
1989
which descriptor methods are defined. A descriptor can define any combination
1986
1990
of :meth: `~object.__get__ `, :meth: `~object.__set__ ` and
1987
1991
:meth: `~object.__delete__ `. If it does not
1988
- define :meth: `__get__ `, then accessing the attribute will return the descriptor
1992
+ define :meth: `! __get__ `, then accessing the attribute will return the descriptor
1989
1993
object itself unless there is a value in the object's instance dictionary. If
1990
- the descriptor defines :meth: `__set__ ` and/or :meth: `__delete__ `, it is a data
1994
+ the descriptor defines :meth: `! __set__ ` and/or :meth: `! __delete__ `, it is a data
1991
1995
descriptor; if it defines neither, it is a non-data descriptor. Normally, data
1992
- descriptors define both :meth: `__get__ ` and :meth: `__set__ `, while non-data
1993
- descriptors have just the :meth: `__get__ ` method. Data descriptors with
1994
- :meth: `__get__ ` and :meth: `__set__ ` (and/or :meth: `__delete__ `) defined always override a redefinition in an
1996
+ descriptors define both :meth: `!__get__ ` and :meth: `!__set__ `, while non-data
1997
+ descriptors have just the :meth: `!__get__ ` method. Data descriptors with
1998
+ :meth: `!__get__ ` and :meth: `!__set__ ` (and/or :meth: `!__delete__ `) defined
1999
+ always override a redefinition in an
1995
2000
instance dictionary. In contrast, non-data descriptors can be overridden by
1996
2001
instances.
1997
2002
@@ -2568,16 +2573,17 @@ either to emulate a sequence or to emulate a mapping; the difference is that for
2568
2573
a sequence, the allowable keys should be the integers *k * for which ``0 <= k <
2569
2574
N `` where *N * is the length of the sequence, or :class: `slice ` objects, which define a
2570
2575
range of items. It is also recommended that mappings provide the methods
2571
- :meth: `keys `, :meth: `values `, :meth: `items `, :meth: `get `, :meth: `clear `,
2572
- :meth: `setdefault `, :meth: `pop `, :meth: `popitem `, :meth: `!copy `, and
2573
- :meth: `update ` behaving similar to those for Python's standard :class: `dictionary <dict> `
2576
+ :meth: `! keys `, :meth: `! values `, :meth: `! items `, :meth: `! get `, :meth: `! clear `,
2577
+ :meth: `! setdefault `, :meth: `! pop `, :meth: `! popitem `, :meth: `!copy `, and
2578
+ :meth: `! update ` behaving similar to those for Python's standard :class: `dictionary <dict> `
2574
2579
objects. The :mod: `collections.abc ` module provides a
2575
2580
:class: `~collections.abc.MutableMapping `
2576
2581
:term: `abstract base class ` to help create those methods from a base set of
2577
- :meth: `~object.__getitem__ `, :meth: `~object.__setitem__ `, :meth: `~object.__delitem__ `, and :meth: `keys `.
2578
- Mutable sequences should provide methods :meth: `append `, :meth: `count `,
2579
- :meth: `index `, :meth: `extend `, :meth: `insert `, :meth: `pop `, :meth: `remove `,
2580
- :meth: `reverse ` and :meth: `sort `, like Python standard :class: `list `
2582
+ :meth: `~object.__getitem__ `, :meth: `~object.__setitem__ `,
2583
+ :meth: `~object.__delitem__ `, and :meth: `!keys `.
2584
+ Mutable sequences should provide methods :meth: `!append `, :meth: `!count `,
2585
+ :meth: `!index `, :meth: `!extend `, :meth: `!insert `, :meth: `!pop `, :meth: `!remove `,
2586
+ :meth: `!reverse ` and :meth: `!sort `, like Python standard :class: `list `
2581
2587
objects. Finally,
2582
2588
sequence types should implement addition (meaning concatenation) and
2583
2589
multiplication (meaning repetition) by defining the methods
@@ -2590,7 +2596,7 @@ operator; for
2590
2596
mappings, ``in `` should search the mapping's keys; for sequences, it should
2591
2597
search through the values. It is further recommended that both mappings and
2592
2598
sequences implement the :meth: `~object.__iter__ ` method to allow efficient iteration
2593
- through the container; for mappings, :meth: `__iter__ ` should iterate
2599
+ through the container; for mappings, :meth: `! __iter__ ` should iterate
2594
2600
through the object's keys; for sequences, it should iterate through the values.
2595
2601
2596
2602
.. method :: object.__len__(self)
@@ -3169,7 +3175,7 @@ generators, coroutines do not directly support iteration.
3169
3175
to the :meth: `~generator.send ` method of the iterator that caused
3170
3176
the coroutine to suspend. The result (return value,
3171
3177
:exc: `StopIteration `, or other exception) is the same as when
3172
- iterating over the :meth: `__await__ ` return value, described above.
3178
+ iterating over the :meth: `! __await__ ` return value, described above.
3173
3179
3174
3180
.. method :: coroutine.throw(value)
3175
3181
coroutine.throw(type[, value[, traceback]])
0 commit comments