@@ -48,7 +48,7 @@ nested recursive function definition doesn't work::
48
48
return g(value-1) + 1
49
49
...
50
50
51
- The function :func: `g ` will always raise a :exc: `NameError ` exception, because
51
+ The function :func: `! g ` will always raise a :exc: `NameError ` exception, because
52
52
the binding of the name ``g `` isn't in either its local namespace or in the
53
53
module-level namespace. This isn't much of a problem in practice (how often do
54
54
you recursively define interior functions like this?), but this also made using
@@ -104,7 +104,7 @@ To make the preceding explanation a bit clearer, here's an example::
104
104
105
105
Line 4 containing the ``exec `` statement is a syntax error, since
106
106
``exec `` would define a new local variable named ``x `` whose value should
107
- be accessed by :func: `g `.
107
+ be accessed by :func: `! g `.
108
108
109
109
This shouldn't be much of a limitation, since ``exec `` is rarely used in
110
110
most Python code (and when it is used, it's often a sign of a poor design
@@ -161,7 +161,7 @@ PEP 207: Rich Comparisons
161
161
162
162
In earlier versions, Python's support for implementing comparisons on user-defined
163
163
classes and extension types was quite simple. Classes could implement a
164
- :meth: `__cmp__ ` method that was given two instances of a class, and could only
164
+ :meth: `! __cmp__ ` method that was given two instances of a class, and could only
165
165
return 0 if they were equal or +1 or -1 if they weren't; the method couldn't
166
166
raise an exception or return anything other than a Boolean value. Users of
167
167
Numeric Python often found this model too weak and restrictive, because in the
@@ -175,21 +175,21 @@ In Python 2.1, rich comparisons were added in order to support this need.
175
175
Python classes can now individually overload each of the ``< ``, ``<= ``, ``> ``,
176
176
``>= ``, ``== ``, and ``!= `` operations. The new magic method names are:
177
177
178
- +-----------+----------------+
179
- | Operation | Method name |
180
- +===========+================+
181
- | ``< `` | :meth: `__lt__ ` |
182
- +-----------+----------------+
183
- | ``<= `` | :meth: `__le__ ` |
184
- +-----------+----------------+
185
- | ``> `` | :meth: `__gt__ ` |
186
- +-----------+----------------+
187
- | ``>= `` | :meth: `__ge__ ` |
188
- +-----------+----------------+
189
- | ``== `` | :meth: `__eq__ ` |
190
- +-----------+----------------+
191
- | ``!= `` | :meth: `__ne__ ` |
192
- +-----------+----------------+
178
+ +-----------+------------------------ +
179
+ | Operation | Method name |
180
+ +===========+======================== +
181
+ | ``< `` | :meth: `~object. __lt__ ` |
182
+ +-----------+------------------------ +
183
+ | ``<= `` | :meth: `~object. __le__ ` |
184
+ +-----------+------------------------ +
185
+ | ``> `` | :meth: `~object. __gt__ ` |
186
+ +-----------+------------------------ +
187
+ | ``>= `` | :meth: `~object. __ge__ ` |
188
+ +-----------+------------------------ +
189
+ | ``== `` | :meth: `~object. __eq__ ` |
190
+ +-----------+------------------------ +
191
+ | ``!= `` | :meth: `~object. __ne__ ` |
192
+ +-----------+------------------------ +
193
193
194
194
(The magic methods are named after the corresponding Fortran operators ``.LT. ``.
195
195
``.LE. ``, &c. Numeric programmers are almost certainly quite familiar with
@@ -208,7 +208,7 @@ The built-in ``cmp(A,B)`` function can use the rich comparison machinery,
208
208
and now accepts an optional argument specifying which comparison operation to
209
209
use; this is given as one of the strings ``"<" ``, ``"<=" ``, ``">" ``, ``">=" ``,
210
210
``"==" ``, or ``"!=" ``. If called without the optional third argument,
211
- :func: `cmp ` will only return -1, 0, or +1 as in previous versions of Python;
211
+ :func: `! cmp ` will only return -1, 0, or +1 as in previous versions of Python;
212
212
otherwise it will call the appropriate method and can return any Python object.
213
213
214
214
There are also corresponding changes of interest to C programmers; there's a new
@@ -245,7 +245,7 @@ out warnings that you don't want to be displayed. Third-party modules can also
245
245
use this framework to deprecate old features that they no longer wish to
246
246
support.
247
247
248
- For example, in Python 2.1 the :mod: `regex ` module is deprecated, so importing
248
+ For example, in Python 2.1 the :mod: `! regex ` module is deprecated, so importing
249
249
it causes a warning to be printed::
250
250
251
251
>>> import regex
@@ -262,7 +262,7 @@ can be used to specify a particular warning category.
262
262
263
263
Filters can be added to disable certain warnings; a regular expression pattern
264
264
can be applied to the message or to the module name in order to suppress a
265
- warning. For example, you may have a program that uses the :mod: `regex ` module
265
+ warning. For example, you may have a program that uses the :mod: `! regex ` module
266
266
and not want to spare the time to convert it to use the :mod: `re ` module right
267
267
now. The warning can be suppressed by calling ::
268
268
@@ -274,7 +274,7 @@ now. The warning can be suppressed by calling ::
274
274
275
275
This adds a filter that will apply only to warnings of the class
276
276
:class: `DeprecationWarning ` triggered in the :mod: `__main__ ` module, and applies
277
- a regular expression to only match the message about the :mod: `regex ` module
277
+ a regular expression to only match the message about the :mod: `! regex ` module
278
278
being deprecated, and will cause such warnings to be ignored. Warnings can also
279
279
be printed only once, printed every time the offending code is executed, or
280
280
turned into exceptions that will cause the program to stop (unless the
@@ -368,7 +368,7 @@ dictionary::
368
368
This version works for simple things such as integers, but it has a side effect;
369
369
the ``_cache `` dictionary holds a reference to the return values, so they'll
370
370
never be deallocated until the Python process exits and cleans up. This isn't
371
- very noticeable for integers, but if :func: `f ` returns an object, or a data
371
+ very noticeable for integers, but if :func: `! f ` returns an object, or a data
372
372
structure that takes up a lot of memory, this can be a problem.
373
373
374
374
Weak references provide a way to implement a cache that won't keep objects alive
@@ -379,7 +379,7 @@ created by calling ``wr = weakref.ref(obj)``. The object being referred to is
379
379
returned by calling the weak reference as if it were a function: ``wr() ``. It
380
380
will return the referenced object, or ``None `` if the object no longer exists.
381
381
382
- This makes it possible to write a :func: `memoize ` function whose cache doesn't
382
+ This makes it possible to write a :func: `! memoize ` function whose cache doesn't
383
383
keep objects alive, by storing weak references in the cache. ::
384
384
385
385
_cache = {}
@@ -402,7 +402,7 @@ weak references --- an object referenced only by proxy objects is deallocated --
402
402
but instead of requiring an explicit call to retrieve the object, the proxy
403
403
transparently forwards all operations to the object as long as the object still
404
404
exists. If the object is deallocated, attempting to use a proxy will cause a
405
- :exc: `weakref.ReferenceError ` exception to be raised. ::
405
+ :exc: `! weakref.ReferenceError ` exception to be raised. ::
406
406
407
407
proxy = weakref.proxy(obj)
408
408
proxy.attr # Equivalent to obj.attr
@@ -446,7 +446,7 @@ The dictionary containing attributes can be accessed as the function's
446
446
:attr: `~object.__dict__ `. Unlike the :attr: `~object.__dict__ ` attribute of class instances, in
447
447
functions you can actually assign a new dictionary to :attr: `~object.__dict__ `, though
448
448
the new value is restricted to a regular Python dictionary; you *can't * be
449
- tricky and set it to a :class: `UserDict ` instance, or any other random object
449
+ tricky and set it to a :class: `! UserDict ` instance, or any other random object
450
450
that behaves like a mapping.
451
451
452
452
@@ -584,11 +584,11 @@ available from the Distutils SIG at https://www.python.org/community/sigs/curren
584
584
New and Improved Modules
585
585
========================
586
586
587
- * Ka-Ping Yee contributed two new modules: :mod: `inspect.py `, a module for
588
- getting information about live Python code, and :mod: `pydoc.py `, a module for
587
+ * Ka-Ping Yee contributed two new modules: :mod: `! inspect.py `, a module for
588
+ getting information about live Python code, and :mod: `! pydoc.py `, a module for
589
589
interactively converting docstrings to HTML or text. As a bonus,
590
590
:file: `Tools/scripts/pydoc `, which is now automatically installed, uses
591
- :mod: `pydoc.py ` to display documentation given a Python module, package, or
591
+ :mod: `! pydoc.py ` to display documentation given a Python module, package, or
592
592
class name. For example, ``pydoc xml.dom `` displays the following::
593
593
594
594
Python Library Documentation: package xml.dom in xml
@@ -617,7 +617,7 @@ New and Improved Modules
617
617
Kent Beck's Smalltalk testing framework. See https://pyunit.sourceforge.net/ for
618
618
more information about PyUnit.
619
619
620
- * The :mod: `difflib ` module contains a class, :class: `SequenceMatcher `, which
620
+ * The :mod: `difflib ` module contains a class, :class: `~difflib. SequenceMatcher `, which
621
621
compares two sequences and computes the changes required to transform one
622
622
sequence into the other. For example, this module can be used to write a tool
623
623
similar to the Unix :program: `diff ` program, and in fact the sample program
@@ -633,7 +633,7 @@ New and Improved Modules
633
633
2.1 includes an updated version of the :mod: `xml ` package. Some of the
634
634
noteworthy changes include support for Expat 1.2 and later versions, the ability
635
635
for Expat parsers to handle files in any encoding supported by Python, and
636
- various bugfixes for SAX, DOM, and the :mod: `minidom ` module.
636
+ various bugfixes for SAX, DOM, and the :mod: `! minidom ` module.
637
637
638
638
* Ping also contributed another hook for handling uncaught exceptions.
639
639
:func: `sys.excepthook ` can be set to a callable object. When an exception isn't
@@ -643,8 +643,8 @@ New and Improved Modules
643
643
printing an extended traceback that not only lists the stack frames, but also
644
644
lists the function arguments and the local variables for each frame.
645
645
646
- * Various functions in the :mod: `time ` module, such as :func: `asctime ` and
647
- :func: `localtime `, require a floating point argument containing the time in
646
+ * Various functions in the :mod: `time ` module, such as :func: `~time. asctime ` and
647
+ :func: `~time. localtime `, require a floating point argument containing the time in
648
648
seconds since the epoch. The most common use of these functions is to work with
649
649
the current time, so the floating point argument has been made optional; when a
650
650
value isn't provided, the current time will be used. For example, log file
@@ -724,10 +724,10 @@ of the more notable changes are:
724
724
a discussion in comp.lang.python.
725
725
726
726
A new module and method for file objects was also added, contributed by Jeff
727
- Epler. The new method, :meth: `xreadlines `, is similar to the existing
728
- :func: `xrange ` built-in. :func: `xreadlines ` returns an opaque sequence object
727
+ Epler. The new method, :meth: `! xreadlines `, is similar to the existing
728
+ :func: `! xrange ` built-in. :func: `! xreadlines ` returns an opaque sequence object
729
729
that only supports being iterated over, reading a line on every iteration but
730
- not reading the entire file into memory as the existing :meth: `readlines ` method
730
+ not reading the entire file into memory as the existing :meth: `! readlines ` method
731
731
does. You'd use it like this::
732
732
733
733
for line in sys.stdin.xreadlines():
@@ -737,7 +737,7 @@ of the more notable changes are:
737
737
For a fuller discussion of the line I/O changes, see the python-dev summary for
738
738
January 1--15, 2001 at https://mail.python.org/pipermail/python-dev/2001-January/.
739
739
740
- * A new method, :meth: `popitem `, was added to dictionaries to enable
740
+ * A new method, :meth: `~dict. popitem `, was added to dictionaries to enable
741
741
destructively iterating through the contents of a dictionary; this can be faster
742
742
for large dictionaries because there's no need to construct a list containing
743
743
all the keys or values. ``D.popitem() `` removes a random ``(key, value) `` pair
0 commit comments