@@ -91,7 +91,7 @@ Attributes may be read-only or writable. In the latter case, assignment to
9191attributes is possible. Module attributes are writable: you can write
9292``modname.the_answer = 42 ``. Writable attributes may also be deleted with the
9393:keyword: `del ` statement. For example, ``del modname.the_answer `` will remove
94- the attribute :attr: `the_answer ` from the object named by ``modname ``.
94+ the attribute :attr: `! the_answer ` from the object named by ``modname ``.
9595
9696Namespaces are created at different moments and have different lifetimes. The
9797namespace containing the built-in names is created when the Python interpreter
@@ -249,7 +249,7 @@ created. This is basically a wrapper around the contents of the namespace
249249created by the class definition; we'll learn more about class objects in the
250250next section. The original local scope (the one in effect just before the class
251251definition was entered) is reinstated, and the class object is bound here to the
252- class name given in the class definition header (:class: `ClassName ` in the
252+ class name given in the class definition header (:class: `! ClassName ` in the
253253example).
254254
255255
@@ -291,20 +291,20 @@ variable ``x``.
291291The instantiation operation ("calling" a class object) creates an empty object.
292292Many classes like to create objects with instances customized to a specific
293293initial state. Therefore a class may define a special method named
294- :meth: `__init__ `, like this::
294+ :meth: `~object. __init__ `, like this::
295295
296296 def __init__(self):
297297 self.data = []
298298
299- When a class defines an :meth: `__init__ ` method, class instantiation
300- automatically invokes :meth: `__init__ ` for the newly created class instance. So
299+ When a class defines an :meth: `~object. __init__ ` method, class instantiation
300+ automatically invokes :meth: `! __init__ ` for the newly created class instance. So
301301in this example, a new, initialized instance can be obtained by::
302302
303303 x = MyClass()
304304
305- Of course, the :meth: `__init__ ` method may have arguments for greater
305+ Of course, the :meth: `~object. __init__ ` method may have arguments for greater
306306flexibility. In that case, arguments given to the class instantiation operator
307- are passed on to :meth: `__init__ `. For example, ::
307+ are passed on to :meth: `! __init__ `. For example, ::
308308
309309 >>> class Complex:
310310 ... def __init__(self, realpart, imagpart):
@@ -328,7 +328,7 @@ attribute names: data attributes and methods.
328328*data attributes * correspond to "instance variables" in Smalltalk, and to "data
329329members" in C++. Data attributes need not be declared; like local variables,
330330they spring into existence when they are first assigned to. For example, if
331- ``x `` is the instance of :class: `MyClass ` created above, the following piece of
331+ ``x `` is the instance of :class: `! MyClass ` created above, the following piece of
332332code will print the value ``16 ``, without leaving a trace::
333333
334334 x.counter = 1
@@ -363,7 +363,7 @@ Usually, a method is called right after it is bound::
363363
364364 x.f()
365365
366- In the :class: `MyClass ` example, this will return the string ``'hello world' ``.
366+ In the :class: `! MyClass ` example, this will return the string ``'hello world' ``.
367367However, it is not necessary to call a method right away: ``x.f `` is a method
368368object, and can be stored away and called at a later time. For example::
369369
@@ -375,7 +375,7 @@ will continue to print ``hello world`` until the end of time.
375375
376376What exactly happens when a method is called? You may have noticed that
377377``x.f() `` was called without an argument above, even though the function
378- definition for :meth: `f ` specified an argument. What happened to the argument?
378+ definition for :meth: `! f ` specified an argument. What happened to the argument?
379379Surely Python raises an exception when a function that requires an argument is
380380called without any --- even if the argument isn't actually used...
381381
@@ -532,9 +532,9 @@ variable in the class is also ok. For example::
532532
533533 h = g
534534
535- Now ``f ``, ``g `` and ``h `` are all attributes of class :class: `C ` that refer to
535+ Now ``f ``, ``g `` and ``h `` are all attributes of class :class: `! C ` that refer to
536536function objects, and consequently they are all methods of instances of
537- :class: `C ` --- ``h `` being exactly equivalent to ``g ``. Note that this practice
537+ :class: `! C ` --- ``h `` being exactly equivalent to ``g ``. Note that this practice
538538usually only serves to confuse the reader of a program.
539539
540540Methods may call other methods by using method attributes of the ``self ``
@@ -581,7 +581,7 @@ this::
581581 .
582582 <statement-N>
583583
584- The name :class: `BaseClassName ` must be defined in a
584+ The name :class: `! BaseClassName ` must be defined in a
585585namespace accessible from the scope containing the
586586derived class definition. In place of a base class name, other arbitrary
587587expressions are also allowed. This can be useful, for example, when the base
@@ -645,9 +645,9 @@ multiple base classes looks like this::
645645For most purposes, in the simplest cases, you can think of the search for
646646attributes inherited from a parent class as depth-first, left-to-right, not
647647searching twice in the same class where there is an overlap in the hierarchy.
648- Thus, if an attribute is not found in :class: `DerivedClassName `, it is searched
649- for in :class: `Base1 `, then (recursively) in the base classes of :class: `Base1 `,
650- and if it was not found there, it was searched for in :class: `Base2 `, and so on.
648+ Thus, if an attribute is not found in :class: `! DerivedClassName `, it is searched
649+ for in :class: `! Base1 `, then (recursively) in the base classes of :class: `! Base1 `,
650+ and if it was not found there, it was searched for in :class: `! Base2 `, and so on.
651651
652652In fact, it is slightly more complex than that; the method resolution order
653653changes dynamically to support cooperative calls to :func: `super `. This
@@ -760,7 +760,8 @@ is to use :mod:`dataclasses` for this purpose::
760760A piece of Python code that expects a particular abstract data type can often be
761761passed a class that emulates the methods of that data type instead. For
762762instance, if you have a function that formats some data from a file object, you
763- can define a class with methods :meth: `read ` and :meth: `!readline ` that get the
763+ can define a class with methods :meth: `~io.TextIOBase.read ` and
764+ :meth: `~io.TextIOBase.readline ` that get the
764765data from a string buffer instead, and pass it as an argument.
765766
766767.. (Unfortunately, this technique has its limitations: a class can't define
@@ -769,7 +770,7 @@ data from a string buffer instead, and pass it as an argument.
769770 not cause the interpreter to read further input from it.)
770771
771772 Instance method objects have attributes, too: ``m.__self__ `` is the instance
772- object with the method :meth: `m `, and ``m.__func__ `` is the function object
773+ object with the method :meth: `! m `, and ``m.__func__ `` is the function object
773774corresponding to the method.
774775
775776
@@ -818,9 +819,9 @@ using the :func:`next` built-in function; this example shows how it all works::
818819 StopIteration
819820
820821Having seen the mechanics behind the iterator protocol, it is easy to add
821- iterator behavior to your classes. Define an :meth: `__iter__ ` method which
822+ iterator behavior to your classes. Define an :meth: `~container. __iter__ ` method which
822823returns an object with a :meth: `~iterator.__next__ ` method. If the class
823- defines :meth: `__next__ `, then :meth: `__iter__ ` can just return ``self ``::
824+ defines :meth: `! __next__ `, then :meth: `! __iter__ ` can just return ``self ``::
824825
825826 class Reverse:
826827 """Iterator for looping over a sequence backwards."""
@@ -879,7 +880,7 @@ easy to create::
879880
880881Anything that can be done with generators can also be done with class-based
881882iterators as described in the previous section. What makes generators so
882- compact is that the :meth: `__iter__ ` and :meth: `~generator.__next__ ` methods
883+ compact is that the :meth: `~iterator. __iter__ ` and :meth: `~generator.__next__ ` methods
883884are created automatically.
884885
885886Another key feature is that the local variables and execution state are
0 commit comments