@@ -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
@@ -1903,13 +1903,17 @@ class' :attr:`~object.__dict__`.
1903
1903
1904
1904
Called to delete the attribute on an instance *instance * of the owner class.
1905
1905
1906
+ Instances of descriptors may also have the :attr: `!__objclass__ ` attribute
1907
+ present:
1906
1908
1907
- The attribute :attr: `__objclass__ ` is interpreted by the :mod: `inspect ` module
1908
- as specifying the class where this object was defined (setting this
1909
- appropriately can assist in runtime introspection of dynamic class attributes).
1910
- For callables, it may indicate that an instance of the given type (or a
1911
- subclass) is expected or required as the first positional argument (for example,
1912
- CPython sets this attribute for unbound methods that are implemented in C).
1909
+ .. attribute :: object.__objclass__
1910
+
1911
+ The attribute :attr: `!__objclass__ ` is interpreted by the :mod: `inspect ` module
1912
+ as specifying the class where this object was defined (setting this
1913
+ appropriately can assist in runtime introspection of dynamic class attributes).
1914
+ For callables, it may indicate that an instance of the given type (or a
1915
+ subclass) is expected or required as the first positional argument (for example,
1916
+ CPython sets this attribute for unbound methods that are implemented in C).
1913
1917
1914
1918
1915
1919
.. _descriptor-invocation :
@@ -1990,13 +1994,14 @@ For instance bindings, the precedence of descriptor invocation depends on
1990
1994
which descriptor methods are defined. A descriptor can define any combination
1991
1995
of :meth: `~object.__get__ `, :meth: `~object.__set__ ` and
1992
1996
:meth: `~object.__delete__ `. If it does not
1993
- define :meth: `__get__ `, then accessing the attribute will return the descriptor
1997
+ define :meth: `! __get__ `, then accessing the attribute will return the descriptor
1994
1998
object itself unless there is a value in the object's instance dictionary. If
1995
- the descriptor defines :meth: `__set__ ` and/or :meth: `__delete__ `, it is a data
1999
+ the descriptor defines :meth: `! __set__ ` and/or :meth: `! __delete__ `, it is a data
1996
2000
descriptor; if it defines neither, it is a non-data descriptor. Normally, data
1997
- descriptors define both :meth: `__get__ ` and :meth: `__set__ `, while non-data
1998
- descriptors have just the :meth: `__get__ ` method. Data descriptors with
1999
- :meth: `__get__ ` and :meth: `__set__ ` (and/or :meth: `__delete__ `) defined always override a redefinition in an
2001
+ descriptors define both :meth: `!__get__ ` and :meth: `!__set__ `, while non-data
2002
+ descriptors have just the :meth: `!__get__ ` method. Data descriptors with
2003
+ :meth: `!__get__ ` and :meth: `!__set__ ` (and/or :meth: `!__delete__ `) defined
2004
+ always override a redefinition in an
2000
2005
instance dictionary. In contrast, non-data descriptors can be overridden by
2001
2006
instances.
2002
2007
@@ -2573,16 +2578,17 @@ either to emulate a sequence or to emulate a mapping; the difference is that for
2573
2578
a sequence, the allowable keys should be the integers *k * for which ``0 <= k <
2574
2579
N `` where *N * is the length of the sequence, or :class: `slice ` objects, which define a
2575
2580
range of items. It is also recommended that mappings provide the methods
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> `
2581
+ :meth: `! keys `, :meth: `! values `, :meth: `! items `, :meth: `! get `, :meth: `! clear `,
2582
+ :meth: `! setdefault `, :meth: `! pop `, :meth: `! popitem `, :meth: `!copy `, and
2583
+ :meth: `! update ` behaving similar to those for Python's standard :class: `dictionary <dict> `
2579
2584
objects. The :mod: `collections.abc ` module provides a
2580
2585
:class: `~collections.abc.MutableMapping `
2581
2586
:term: `abstract base class ` to help create those methods from a base set of
2582
- :meth: `~object.__getitem__ `, :meth: `~object.__setitem__ `, :meth: `~object.__delitem__ `, and :meth: `keys `.
2583
- Mutable sequences should provide methods :meth: `append `, :meth: `count `,
2584
- :meth: `index `, :meth: `extend `, :meth: `insert `, :meth: `pop `, :meth: `remove `,
2585
- :meth: `reverse ` and :meth: `sort `, like Python standard :class: `list `
2587
+ :meth: `~object.__getitem__ `, :meth: `~object.__setitem__ `,
2588
+ :meth: `~object.__delitem__ `, and :meth: `!keys `.
2589
+ Mutable sequences should provide methods :meth: `!append `, :meth: `!count `,
2590
+ :meth: `!index `, :meth: `!extend `, :meth: `!insert `, :meth: `!pop `, :meth: `!remove `,
2591
+ :meth: `!reverse ` and :meth: `!sort `, like Python standard :class: `list `
2586
2592
objects. Finally,
2587
2593
sequence types should implement addition (meaning concatenation) and
2588
2594
multiplication (meaning repetition) by defining the methods
@@ -2595,7 +2601,7 @@ operator; for
2595
2601
mappings, ``in `` should search the mapping's keys; for sequences, it should
2596
2602
search through the values. It is further recommended that both mappings and
2597
2603
sequences implement the :meth: `~object.__iter__ ` method to allow efficient iteration
2598
- through the container; for mappings, :meth: `__iter__ ` should iterate
2604
+ through the container; for mappings, :meth: `! __iter__ ` should iterate
2599
2605
through the object's keys; for sequences, it should iterate through the values.
2600
2606
2601
2607
.. method :: object.__len__(self)
@@ -3174,7 +3180,7 @@ generators, coroutines do not directly support iteration.
3174
3180
to the :meth: `~generator.send ` method of the iterator that caused
3175
3181
the coroutine to suspend. The result (return value,
3176
3182
:exc: `StopIteration `, or other exception) is the same as when
3177
- iterating over the :meth: `__await__ ` return value, described above.
3183
+ iterating over the :meth: `! __await__ ` return value, described above.
3178
3184
3179
3185
.. method :: coroutine.throw(value)
3180
3186
coroutine.throw(type[, value[, traceback]])
0 commit comments