@@ -56,7 +56,7 @@ Python 2.6 incorporates new features and syntax from 3.0 while
5656remaining compatible with existing code by not removing older features
5757or syntax.  When it's not possible to do that, Python 2.6 tries to do
5858what it can, adding compatibility functions in a
59- :mod: `future_builtins ` module and a :option: `!-3 ` switch to warn about
59+ :mod: `! future_builtins ` module and a :option: `!-3 ` switch to warn about
6060usages that will become unsupported in 3.0.
6161
6262Some significant new packages have been added to the standard library,
109109Python 3.0 adds several new built-in functions and changes the
110110semantics of some existing builtins.  Functions that are new in 3.0
111111such as :func: `bin ` have simply been added to Python 2.6, but existing
112- builtins haven't been changed; instead, the :mod: `future_builtins `
112+ builtins haven't been changed; instead, the :mod: `! future_builtins `
113113module has versions with the new 3.0 semantics.  Code written to be
114114compatible with 3.0 can do ``from future_builtins import hex, map `` as
115115necessary.
@@ -118,7 +118,7 @@ A new command-line switch, :option:`!-3`, enables warnings
118118about features that will be removed in Python 3.0.  You can run code
119119with this switch to see how much work will be necessary to port
120120code to 3.0.  The value of this switch is available
121- to Python code as the boolean variable :data: `sys.py3kwarning `,
121+ to Python code as the boolean variable :data: `! sys.py3kwarning `,
122122and to C extension code as :c:data: `!Py_Py3kWarningFlag `.
123123
124124.. seealso ::
@@ -307,9 +307,9 @@ The :mod:`threading` module's locks and condition variables  also support the
307307The lock is acquired before the block is executed and always released once  the
308308block is complete.
309309
310- The :func: `localcontext ` function in the :mod: `decimal ` module makes it easy 
311- to save and restore the current decimal context, which encapsulates the desired 
312- precision and rounding characteristics for computations::
310+ The :func: `~decimal. localcontext ` function in the :mod: `decimal ` module makes
311+ it easy  to save and restore the current decimal context, which encapsulates
312+ the desired  precision and rounding characteristics for computations::
313313
314314   from decimal import Decimal, Context, localcontext 
315315
@@ -337,12 +337,12 @@ underlying implementation and should keep reading.
337337A high-level explanation of the context management protocol is:
338338
339339* The expression is evaluated and should result in an object called a "context
340-   manager".  The context manager must have :meth: `~object.__enter__ ` and  :meth: ` ~object.__exit__ ` 
341-   methods.
340+   manager".  The context manager must have :meth: `~object.__enter__ ` and
341+   :meth: ` ~object.__exit__ `  methods.
342342
343- * The context manager's :meth: `~object.__enter__ ` method is called.  The value returned 
344-   is assigned to *VAR *.  If no ``as VAR `` clause is present, the value is simply 
345-   discarded.
343+ * The context manager's :meth: `~object.__enter__ ` method is called.  The value
344+   returned  is assigned to *VAR *.  If no ``as VAR `` clause is present, the
345+   value is simply  discarded.
346346
347347* The code in *BLOCK * is executed.
348348
@@ -378,7 +378,7 @@ be to let the user write code like this::
378378
379379The transaction should be committed if the code in the block runs flawlessly or
380380rolled back if there's an exception. Here's the basic interface for
381- :class: `DatabaseConnection ` that I'll assume::
381+ :class: `! DatabaseConnection ` that I'll assume::
382382
383383   class DatabaseConnection: 
384384       # Database interface 
@@ -431,14 +431,15 @@ The contextlib module
431431The :mod: `contextlib ` module provides some functions and a decorator that
432432are useful when writing objects for use with the ':keyword: `with `' statement.
433433
434- The decorator is called :func: `contextmanager `, and lets you write a single
435- generator function instead of defining a new class.  The generator should yield
436- exactly one value.  The code up to the :keyword: `yield ` will be executed as the
437- :meth: `~object.__enter__ ` method, and the value yielded will be the method's return
438- value that will get bound to the variable in the ':keyword: `with `' statement's
439- :keyword: `!as ` clause, if any.  The code after the :keyword: `!yield ` will be
440- executed in the :meth: `~object.__exit__ ` method.  Any exception raised in the block will
441- be raised by the :keyword: `!yield ` statement.
434+ The decorator is called :func: `~contextlib.contextmanager `, and lets you write
435+ a single generator function instead of defining a new class.  The generator
436+ should yield exactly one value.  The code up to the :keyword: `yield ` will be
437+ executed as the :meth: `~object.__enter__ ` method, and the value yielded will
438+ be the method's return value that will get bound to the variable in the
439+ ':keyword: `with `' statement's :keyword: `!as ` clause, if any.  The code after
440+ the :keyword: `!yield ` will be executed in the :meth: `~object.__exit__ ` method.
441+ Any exception raised in the block will be raised by the :keyword: `!yield `
442+ statement.
442443
443444Using this decorator, our database example from the previous section
444445could be written as::
@@ -469,7 +470,7 @@ statement both starts a database transaction and acquires a thread lock::
469470   with nested (db_transaction(db), lock) as (cursor, locked): 
470471       ... 
471472
472- Finally, the :func: `closing ` function returns its argument so that it can be
473+ Finally, the :func: `~contextlib. closing ` function returns its argument so that it can be
473474bound to a variable, and calls the argument's ``.close() `` method at the end
474475of the block. ::
475476
@@ -538,7 +539,7 @@ If you don't like the default directory, it can be overridden by an
538539environment variable.  :envvar: `PYTHONUSERBASE ` sets the root
539540directory used for all Python versions supporting this feature.  On
540541Windows, the directory for application-specific data can be changed by
541- setting the :envvar: `APPDATA ` environment variable.  You can also
542+ setting the :envvar: `! APPDATA ` environment variable.  You can also
542543modify the :file: `site.py ` file for your Python installation.
543544
544545The feature can be disabled entirely by running Python with the
@@ -568,11 +569,12 @@ The :mod:`multiprocessing` module started out as an exact emulation of
568569the :mod: `threading ` module using processes instead of threads.  That
569570goal was discarded along the path to Python 2.6, but the general
570571approach of the module is still similar.  The fundamental class
571- is the :class: `Process `, which is passed a callable object and
572- a collection of arguments.  The :meth: `start ` method
572+ is the :class: `~multiprocessing. Process `, which is passed a callable object and
573+ a collection of arguments.  The :meth: `~multiprocessing.Process. start ` method
573574sets the callable running in a subprocess, after which you can call
574- the :meth: `is_alive ` method to check whether the subprocess is still running
575- and the :meth: `join ` method to wait for the process to exit.
575+ the :meth: `~multiprocessing.Process.is_alive ` method to check whether the
576+ subprocess is still running and the :meth: `~multiprocessing.Process.join `
577+ method to wait for the process to exit.
576578
577579Here's a simple example where the subprocess will calculate a
578580factorial.  The function doing the calculation is written strangely so
@@ -619,13 +621,16 @@ the object to communicate.  (If the parent were to change the value of
619621the global variable, the child's value would be unaffected, and vice
620622versa.)
621623
622- Two other classes, :class: `Pool ` and :class: `Manager `, provide
623- higher-level interfaces.  :class: `Pool ` will create a fixed number of
624- worker processes, and requests can then be distributed to the workers
625- by calling :meth: `apply ` or :meth: `apply_async ` to add a single request,
626- and :meth: `map ` or :meth: `map_async ` to add a number of
627- requests.  The following code uses a :class: `Pool ` to spread requests
628- across 5 worker processes and retrieve a list of results::
624+ Two other classes, :class: `~multiprocessing.pool.Pool ` and
625+ :class: `~multiprocessing.Manager `, provide higher-level interfaces.
626+ :class: `~multiprocessing.pool.Pool ` will create a fixed number of worker
627+ processes, and requests can then be distributed to the workers by calling
628+ :meth: `~multiprocessing.pool.Pool.apply ` or
629+ :meth: `~multiprocessing.pool.Pool.apply_async ` to add a single request, and
630+ :meth: `~multiprocessing.pool.Pool.map ` or
631+ :meth: `~multiprocessing.pool.Pool.map_async ` to add a number of
632+ requests.  The following code uses a :class: `~multiprocessing.pool.Pool ` to
633+ spread requests across 5 worker processes and retrieve a list of results::
629634
630635    from multiprocessing import Pool 
631636
@@ -646,15 +651,18 @@ This produces the following output::
646651    33452526613163807108170062053440751665152000000000 
647652    ... 
648653
649- The other high-level interface, the :class: `Manager ` class, creates a 
650- separate server process that can hold master copies of Python data
654+ The other high-level interface, the :class: `~multiprocessing. Manager ` class,
655+ creates a  separate server process that can hold master copies of Python data
651656structures.  Other processes can then access and modify these data
652657structures using proxy objects.  The following example creates a
653658shared dictionary by calling the :meth: `dict ` method; the worker
654659processes then insert values into the dictionary.  (Locking is not
655660done for you automatically, which doesn't matter in this example.
656- :class: `Manager `'s methods also include :meth: `Lock `, :meth: `RLock `,
657- and :meth: `Semaphore ` to create shared locks.)
661+ :class: `~multiprocessing.Manager `'s methods also include
662+ :meth: `~multiprocessing.managers.SyncManager.Lock `,
663+ :meth: `~multiprocessing.managers.SyncManager.RLock `,
664+ and :meth: `~multiprocessing.managers.SyncManager.Semaphore ` to create
665+ shared locks.)
658666
659667::
660668
@@ -824,7 +832,7 @@ documentation for a :ref:`complete list <formatstrings>`; here's a sample:
824832      format, followed by a percent sign.
825833===== ======================================================================== 
826834
827- Classes and types can define a :meth: `__format__ ` method to control how they're
835+ Classes and types can define a :meth: `~object. __format__ ` method to control how they're
828836formatted.  It receives a single argument, the format specifier::
829837
830838   def __format__(self, format_spec): 
@@ -834,7 +842,7 @@ formatted.  It receives a single argument, the format specifier::
834842           return str(self) 
835843
836844There's also a :func: `format ` builtin that will format a single
837- value.  It calls the type's :meth: `__format__ ` method with the
845+ value.  It calls the type's :meth: `~object. __format__ ` method with the
838846provided specifier::
839847
840848    >>> format(75.6564, '.2f') 
@@ -1029,56 +1037,58 @@ PEP 3116: New I/O Library
10291037
10301038Python's built-in file objects support a number of methods, but
10311039file-like objects don't necessarily support all of them.  Objects that
1032- imitate files usually support :meth: `read ` and  :meth: ` write `, but they 
1033- may not support :meth: `readline `, for example.  Python 3.0 introduces 
1034- a layered I/O library in the :mod: `io ` module that separates buffering 
1035- and text-handling features from the fundamental read and write 
1036- operations.
1040+ imitate files usually support :meth: `! read ` and
1041+ :meth: ` !write `, but they  may not support :meth: `! readline `,
1042+ for example.  Python 3.0 introduces  a layered I/O library in the :mod: `io `
1043+ module that separates buffering  and text-handling features from the
1044+ fundamental read and write  operations.
10371045
10381046There are three levels of abstract base classes provided by
10391047the :mod: `io ` module:
10401048
1041- * :class: `RawIOBase ` defines raw I/O operations: :meth: `read `,
1042-   :meth: `readinto `,
1043-   :meth: `write `,  :meth: ` seek `, :meth: `tell `, :meth: `truncate `,
1044-   and :meth: `close `.
1049+ * :class: `~io. RawIOBase ` defines raw I/O operations: :meth: `~io.RawIOBase. read `,
1050+   :meth: `~io.RawIOBase. readinto`,  :meth: ` ~io.RawIOBase.write `,
1051+   :meth: `~io.IOBase. seek `, :meth: `~io.IOBase. tell `, :meth: `~io.IOBase. truncate `,
1052+   and :meth: `~io.IOBase. close `.
10451053  Most of the methods of this class will often map to a single system call.
1046-   There are also :meth: `readable `, :meth: `writable `, and :meth: `seekable `
1047-   methods for determining what operations a given object will allow.
1054+   There are also :meth: `~io.IOBase.readable `, :meth: `~io.IOBase.writable `,
1055+   and :meth: `~io.IOBase.seekable ` methods for determining what operations a
1056+   given object will allow.
10481057
10491058  Python 3.0 has concrete implementations of this class for files and
10501059  sockets, but Python 2.6 hasn't restructured its file and socket objects
10511060  in this way.
10521061
1053- * :class: `BufferedIOBase ` is an abstract base class that
1062+ * :class: `~io. BufferedIOBase ` is an abstract base class that
10541063  buffers data in memory to reduce the number of
10551064  system calls used, making I/O processing more efficient.
1056-   It supports all of the methods of :class: `RawIOBase `,
1057-   and adds a :attr: `raw ` attribute holding the underlying raw object.
1065+   It supports all of the methods of :class: `~io.RawIOBase `,
1066+   and adds a :attr: `~io.BufferedIOBase.raw ` attribute holding the underlying
1067+   raw object.
10581068
10591069  There are five concrete classes implementing this ABC.
1060-   :class: `BufferedWriter ` and :class: `BufferedReader ` are for objects
1061-   that support write-only or read-only usage that have a :meth: `seek `
1062-   method for random access.  :class: `BufferedRandom ` objects support
1070+   :class: `~io. BufferedWriter ` and :class: `~io. BufferedReader ` are for objects
1071+   that support write-only or read-only usage that have a :meth: `~io.IOBase. seek `
1072+   method for random access.  :class: `~io. BufferedRandom ` objects support
10631073  read and write access upon the same underlying stream, and
1064-   :class: `BufferedRWPair ` is for objects such as TTYs that have both
1074+   :class: `~io. BufferedRWPair ` is for objects such as TTYs that have both
10651075  read and write operations acting upon unconnected streams of data.
1066-   The :class: `BytesIO ` class supports reading, writing, and seeking
1076+   The :class: `~io. BytesIO ` class supports reading, writing, and seeking
10671077  over an in-memory buffer.
10681078
10691079  .. index ::
10701080     single: universal newlines; What's new
10711081
1072- * :class: `TextIOBase `: Provides functions for reading and writing
1082+ * :class: `~io. TextIOBase `: Provides functions for reading and writing
10731083  strings (remember, strings will be Unicode in Python 3.0),
1074-   and supporting :term: `universal newlines `.  :class: `TextIOBase ` defines
1084+   and supporting :term: `universal newlines `.  :class: `~io. TextIOBase ` defines
10751085  the :meth: `readline ` method and supports iteration upon
10761086  objects.
10771087
1078-   There are two concrete implementations.  :class: `TextIOWrapper `
1088+   There are two concrete implementations.  :class: `~io. TextIOWrapper `
10791089  wraps a buffered I/O object, supporting all of the methods for
1080-   text I/O and adding a :attr: `buffer ` attribute for access
1081-   to the underlying object.  :class: `StringIO ` simply buffers
1090+   text I/O and adding a :attr: `~io.TextIOBase. buffer ` attribute for access
1091+   to the underlying object.  :class: `~io. StringIO ` simply buffers
10821092  everything in memory without ever writing anything to disk.
10831093
10841094  (In Python 2.6, :class: `io.StringIO ` is implemented in
@@ -1162,7 +1172,7 @@ Some object-oriented languages such as Java support interfaces,
11621172declaring that a class has a given set of methods or supports a given
11631173access protocol.  Abstract Base Classes (or ABCs) are an equivalent
11641174feature for Python. The ABC support consists of an :mod: `abc ` module
1165- containing a metaclass called :class: `ABCMeta `, special handling of
1175+ containing a metaclass called :class: `~abc. ABCMeta `, special handling of
11661176this metaclass by the :func: `isinstance ` and :func: `issubclass `
11671177builtins, and a collection of basic ABCs that the Python developers
11681178think will be widely useful.  Future versions of Python will probably
@@ -1172,17 +1182,17 @@ Let's say you have a particular class and wish to know whether it supports
11721182dictionary-style access.  The phrase "dictionary-style" is vague, however.
11731183It probably means that accessing items with ``obj[1] `` works.
11741184Does it imply that setting items with ``obj[2] = value `` works?
1175- Or that the object will have :meth: `keys `, :meth: `values `, and :meth: `items `
1176- methods?  What about the iterative variants  such as :meth: `iterkeys `?   :meth: ` copy ` 
1177- and :meth: `update `?  Iterating over the object with :func: `iter `?
1185+ Or that the object will have :meth: `! keys `, :meth: `! values `, and :meth: `! items `
1186+ methods?  What about the iterative variants  such as :meth: `! iterkeys `?
1187+ :meth: ` !copy` and :meth: `! update`?  Iterating over the object with :func: `! iter `?
11781188
11791189The Python 2.6 :mod: `collections ` module includes a number of
11801190different ABCs that represent these distinctions.  :class: `Iterable `
1181- indicates that a class defines :meth: `__iter__ `, and
1182- :class: `Container ` means the class defines a :meth: `__contains__ `
1191+ indicates that a class defines :meth: `~object. __iter__ `, and
1192+ :class: `Container ` means the class defines a :meth: `~object. __contains__ `
11831193method and therefore supports ``x in y `` expressions.  The basic
11841194dictionary interface of getting items, setting items, and
1185- :meth: `keys `, :meth: `values `, and :meth: `items `, is defined by the
1195+ :meth: `! keys `, :meth: `! values `, and :meth: `! items `, is defined by the
11861196:class: `MutableMapping ` ABC.
11871197
11881198You can derive your own classes from a particular ABC
@@ -1196,7 +1206,7 @@ to indicate they support that ABC's interface::
11961206
11971207Alternatively, you could write the class without deriving from
11981208the desired ABC and instead register the class by
1199- calling the ABC's :meth: `register ` method::
1209+ calling the ABC's :meth: `~abc.ABCMeta. register ` method::
12001210
12011211    import collections 
12021212
@@ -1206,10 +1216,10 @@ calling the ABC's :meth:`register` method::
12061216    collections.MutableMapping.register(Storage) 
12071217
12081218For classes that you write, deriving from the ABC is probably clearer.
1209- The :meth: `register `  method is useful when you've written a new
1219+ The :meth: `~abc.ABCMeta. register `  method is useful when you've written a new
12101220ABC that can describe an existing type or class, or if you want
12111221to declare that some third-party class implements an ABC.
1212- For example, if you defined a :class: `PrintableType ` ABC,
1222+ For example, if you defined a :class: `! PrintableType ` ABC,
12131223it's legal to do::
12141224
12151225  # Register Python's types 
@@ -1256,16 +1266,16 @@ metaclass in a class definition::
12561266            ... 
12571267
12581268
1259- In the :class: `Drawable ` ABC above, the :meth: `draw_doubled ` method
1269+ In the :class: `! Drawable ` ABC above, the :meth: `! draw_doubled ` method
12601270renders the object at twice its size and can be implemented in terms
1261- of other methods described in :class: `Drawable `.  Classes implementing
1271+ of other methods described in :class: `! Drawable `.  Classes implementing
12621272this ABC therefore don't need to provide their own implementation
1263- of :meth: `draw_doubled `, though they can do so.  An implementation
1264- of :meth: `draw ` is necessary, though; the ABC can't provide
1273+ of :meth: `! draw_doubled `, though they can do so.  An implementation
1274+ of :meth: `! draw ` is necessary, though; the ABC can't provide
12651275a useful generic implementation.
12661276
1267- You can apply the `` @ abstractmethod` ` decorator to methods such as
1268- :meth: `draw ` that must be implemented; Python will then raise an
1277+ You can apply the :deco: ` ~abc. abstractmethod ` decorator to methods such as
1278+ :meth: `! draw ` that must be implemented; Python will then raise an
12691279exception for classes that don't define the method.
12701280Note that the exception is only raised when you actually
12711281try to create an instance of a subclass lacking the method::
@@ -1289,7 +1299,7 @@ Abstract data attributes can be declared using the
12891299    def readonly(self): 
12901300       return self._x 
12911301
1292- Subclasses must then define a :meth: ` readonly ` property.
1302+ Subclasses must then define a `` readonly ` ` property.
12931303
12941304.. seealso ::
12951305
@@ -2739,13 +2749,13 @@ numbers.
27392749
27402750..  ======================================================================
27412751
2742-  The :mod: `future_builtins ` module
2752+  The :mod: `! future_builtins ` module
27432753-------------------------------------- 
27442754
27452755Python 3.0 makes many changes to the repertoire of built-in
27462756functions, and most of the changes can't be introduced in the Python
274727572.x series because they would break compatibility.
2748- The :mod: `future_builtins ` module provides versions
2758+ The :mod: `! future_builtins ` module provides versions
27492759of these built-in functions that can be imported when writing
275027603.0-compatible code.
27512761
0 commit comments