@@ -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
@@ -674,8 +674,8 @@ underlying the class method.
674
674
When an instance method object is called, the underlying function
675
675
(:attr: `__func__ `) is called, inserting the class instance
676
676
(:attr: `__self__ `) in front of the argument list. For instance, when
677
- :class: `C ` is a class which contains a definition for a function
678
- :meth: `f `, and ``x `` is an instance of :class: `C `, calling ``x.f(1) `` is
677
+ :class: `! C ` is a class which contains a definition for a function
678
+ :meth: `! f `, and ``x `` is an instance of :class: `! C `, calling ``x.f(1) `` is
679
679
equivalent to calling ``C.f(x, 1) ``.
680
680
681
681
When an instance method object is derived from a class method object, the
@@ -788,7 +788,7 @@ Classes
788
788
Classes are callable. These objects normally act as factories for new
789
789
instances of themselves, but variations are possible for class types that
790
790
override :meth: `~object.__new__ `. The arguments of the call are passed to
791
- :meth: `__new__ ` and, in the typical case, to :meth: `~object.__init__ ` to
791
+ :meth: `! __new__ ` and, in the typical case, to :meth: `~object.__init__ ` to
792
792
initialize the new instance.
793
793
794
794
@@ -892,9 +892,9 @@ https://www.python.org/download/releases/2.3/mro/.
892
892
pair: object; dictionary
893
893
pair: class; attribute
894
894
895
- When a class attribute reference (for class :class: `C `, say) would yield a
895
+ When a class attribute reference (for class :class: `! C `, say) would yield a
896
896
class method object, it is transformed into an instance method object whose
897
- :attr: `__self__ ` attribute is :class: `C `. When it would yield a static
897
+ :attr: `__self__ ` attribute is :class: `! C `. When it would yield a static
898
898
method object, it is transformed into the object wrapped by the static method
899
899
object. See section :ref: `descriptors ` for another way in which attributes
900
900
retrieved from a class may differ from those actually contained in its
@@ -1883,13 +1883,17 @@ class' :attr:`~object.__dict__`.
1883
1883
1884
1884
Called to delete the attribute on an instance *instance * of the owner class.
1885
1885
1886
+ Instances of descriptors may also have the :attr: `!__objclass__ ` attribute
1887
+ present:
1886
1888
1887
- The attribute :attr: `__objclass__ ` is interpreted by the :mod: `inspect ` module
1888
- as specifying the class where this object was defined (setting this
1889
- appropriately can assist in runtime introspection of dynamic class attributes).
1890
- For callables, it may indicate that an instance of the given type (or a
1891
- subclass) is expected or required as the first positional argument (for example,
1892
- CPython sets this attribute for unbound methods that are implemented in C).
1889
+ .. attribute :: object.__objclass__
1890
+
1891
+ The attribute :attr: `!__objclass__ ` is interpreted by the :mod: `inspect ` module
1892
+ as specifying the class where this object was defined (setting this
1893
+ appropriately can assist in runtime introspection of dynamic class attributes).
1894
+ For callables, it may indicate that an instance of the given type (or a
1895
+ subclass) is expected or required as the first positional argument (for example,
1896
+ CPython sets this attribute for unbound methods that are implemented in C).
1893
1897
1894
1898
1895
1899
.. _descriptor-invocation :
@@ -1970,13 +1974,14 @@ For instance bindings, the precedence of descriptor invocation depends on
1970
1974
which descriptor methods are defined. A descriptor can define any combination
1971
1975
of :meth: `~object.__get__ `, :meth: `~object.__set__ ` and
1972
1976
:meth: `~object.__delete__ `. If it does not
1973
- define :meth: `__get__ `, then accessing the attribute will return the descriptor
1977
+ define :meth: `! __get__ `, then accessing the attribute will return the descriptor
1974
1978
object itself unless there is a value in the object's instance dictionary. If
1975
- the descriptor defines :meth: `__set__ ` and/or :meth: `__delete__ `, it is a data
1979
+ the descriptor defines :meth: `! __set__ ` and/or :meth: `! __delete__ `, it is a data
1976
1980
descriptor; if it defines neither, it is a non-data descriptor. Normally, data
1977
- descriptors define both :meth: `__get__ ` and :meth: `__set__ `, while non-data
1978
- descriptors have just the :meth: `__get__ ` method. Data descriptors with
1979
- :meth: `__get__ ` and :meth: `__set__ ` (and/or :meth: `__delete__ `) defined always override a redefinition in an
1981
+ descriptors define both :meth: `!__get__ ` and :meth: `!__set__ `, while non-data
1982
+ descriptors have just the :meth: `!__get__ ` method. Data descriptors with
1983
+ :meth: `!__get__ ` and :meth: `!__set__ ` (and/or :meth: `!__delete__ `) defined
1984
+ always override a redefinition in an
1980
1985
instance dictionary. In contrast, non-data descriptors can be overridden by
1981
1986
instances.
1982
1987
@@ -2549,16 +2554,17 @@ either to emulate a sequence or to emulate a mapping; the difference is that for
2549
2554
a sequence, the allowable keys should be the integers *k * for which ``0 <= k <
2550
2555
N `` where *N * is the length of the sequence, or :class: `slice ` objects, which define a
2551
2556
range of items. It is also recommended that mappings provide the methods
2552
- :meth: `keys `, :meth: `values `, :meth: `items `, :meth: `get `, :meth: `clear `,
2553
- :meth: `setdefault `, :meth: `pop `, :meth: `popitem `, :meth: `!copy `, and
2554
- :meth: `update ` behaving similar to those for Python's standard :class: `dictionary <dict> `
2557
+ :meth: `! keys `, :meth: `! values `, :meth: `! items `, :meth: `! get `, :meth: `! clear `,
2558
+ :meth: `! setdefault `, :meth: `! pop `, :meth: `! popitem `, :meth: `!copy `, and
2559
+ :meth: `! update ` behaving similar to those for Python's standard :class: `dictionary <dict> `
2555
2560
objects. The :mod: `collections.abc ` module provides a
2556
2561
:class: `~collections.abc.MutableMapping `
2557
2562
:term: `abstract base class ` to help create those methods from a base set of
2558
- :meth: `~object.__getitem__ `, :meth: `~object.__setitem__ `, :meth: `~object.__delitem__ `, and :meth: `keys `.
2559
- Mutable sequences should provide methods :meth: `append `, :meth: `count `,
2560
- :meth: `index `, :meth: `extend `, :meth: `insert `, :meth: `pop `, :meth: `remove `,
2561
- :meth: `reverse ` and :meth: `sort `, like Python standard :class: `list `
2563
+ :meth: `~object.__getitem__ `, :meth: `~object.__setitem__ `,
2564
+ :meth: `~object.__delitem__ `, and :meth: `!keys `.
2565
+ Mutable sequences should provide methods :meth: `!append `, :meth: `!count `,
2566
+ :meth: `!index `, :meth: `!extend `, :meth: `!insert `, :meth: `!pop `, :meth: `!remove `,
2567
+ :meth: `!reverse ` and :meth: `!sort `, like Python standard :class: `list `
2562
2568
objects. Finally,
2563
2569
sequence types should implement addition (meaning concatenation) and
2564
2570
multiplication (meaning repetition) by defining the methods
@@ -2571,7 +2577,7 @@ operator; for
2571
2577
mappings, ``in `` should search the mapping's keys; for sequences, it should
2572
2578
search through the values. It is further recommended that both mappings and
2573
2579
sequences implement the :meth: `~object.__iter__ ` method to allow efficient iteration
2574
- through the container; for mappings, :meth: `__iter__ ` should iterate
2580
+ through the container; for mappings, :meth: `! __iter__ ` should iterate
2575
2581
through the object's keys; for sequences, it should iterate through the values.
2576
2582
2577
2583
.. method :: object.__len__(self)
@@ -3109,7 +3115,7 @@ generators, coroutines do not directly support iteration.
3109
3115
to the :meth: `~generator.send ` method of the iterator that caused
3110
3116
the coroutine to suspend. The result (return value,
3111
3117
:exc: `StopIteration `, or other exception) is the same as when
3112
- iterating over the :meth: `__await__ ` return value, described above.
3118
+ iterating over the :meth: `! __await__ ` return value, described above.
3113
3119
3114
3120
.. method :: coroutine.throw(value)
3115
3121
coroutine.throw(type[, value[, traceback]])
0 commit comments