Skip to content

Commit b4d4480

Browse files
committed
More doc formatting tweaks
1 parent e6106b9 commit b4d4480

9 files changed

Lines changed: 148 additions & 109 deletions

File tree

docs/source/automatic_conversion.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
Automatic conversion with ``futurize``
44
======================================
55

6-
The ``future`` source tree includes an experimental script called ``futurize``
7-
to aid in making either Python 2 code or Python 3 code compatible with both
8-
platforms using the ``future`` module. It is based on 2to3 and uses fixers from
9-
``lib2to3``, ``lib3to2``, and ``python-modernize``.
6+
The ``future`` source tree includes an experimental script called
7+
``futurize`` to aid in making either Python 2 code or Python 3 code
8+
compatible with both platforms using the :mod:`future` module. It is
9+
based on 2to3 and uses fixers from ``lib2to3``, ``lib3to2``, and
10+
``python-modernize``.
1011

1112
For Python 2 code (the default), it runs the code through all the
1213
appropriate 2to3 fixers to turn it into valid Python 3 code, and then
@@ -42,6 +43,8 @@ into this code which runs on both Py2 and Py3::
4243
print('Hello', end=' ')
4344

4445

46+
To write out all the changes to your Python files that ``futurize`` suggests, use the ``-w`` flag.
47+
4548
.. _backwards-conversion:
4649

4750
Backwards: 3 to both
@@ -69,10 +72,12 @@ into this code which runs on both Py2 and Py3::
6972
Notice that in both cases ``futurize`` forces a new-style class and
7073
imports the renamed stdlib module under its Py3 name.
7174

72-
It also handles the following Python 3 features:
75+
``futurize --from3`` also handles the following Python 3 features:
7376

7477
- keyword-only arguments
75-
- metaclasses (using ``future.utils.with_metaclass``)
78+
- metaclasses (using :func:`~future.utils.with_metaclass`)
79+
- function annotations (PEP 3107)
80+
- extended tuple unpacking (PEP 3132)
7681

7782

7883
How well does ``futurize`` work?

docs/source/bind_method.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
.. _bind-method:
2+
13
Binding a method to a class
24
---------------------------
35

4-
Python 2 draws a distinction between bound and unbound methods, whereas in Python
5-
3 this distinction is gone: unbound methods have been removed from the
6-
language. To bind a method to a class compatibly across Python 3 and Python 2,
7-
you can use this helper function::
6+
Python 2 draws a distinction between bound and unbound methods, whereas
7+
in Python 3 this distinction is gone: unbound methods have been removed
8+
from the language. To bind a method to a class compatibly across Python
9+
3 and Python 2, you can use this helper function::
810

911
from future.utils import bind_method
1012
@@ -20,8 +22,8 @@ you can use this helper function::
2022
g.greet('Hi!')
2123

2224

23-
On Python 3, calling ``bind_method(cls, name, func)`` is equivalent to calling
24-
``setattr(cls, name, func)``. On Python 2 it is equivalent to::
25+
On Python 3, calling ``bind_method(cls, name, func)`` is equivalent to
26+
calling ``setattr(cls, name, func)``. On Python 2 it is equivalent to::
2527
2628
import types
2729
setattr(cls, name, types.MethodType(func, None, cls))

docs/source/bytes_object.rst

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
bytes
44
-----
55

6-
Handling ``bytes`` consistently and correctly has traditionally been one of the
7-
most difficult tasks in writing a Py3/2 compatible codebase. This is because
8-
the Python 2 ``bytes`` object is simply an alias for Python 2's ``str``, rather
9-
than a true implementation of the Python 3 ``bytes`` object, which is
10-
substantially different.
11-
12-
``future`` contains a backport of the ``bytes`` object from Python 3 which
13-
passes most of the Python 3 tests for ``bytes``. (See
6+
Handling ``bytes`` consistently and correctly has traditionally been one
7+
of the most difficult tasks in writing a Py3/2 compatible codebase. This
8+
is because the Python 2 :class:`bytes` object is simply an alias for
9+
Python 2's :class:`str`, rather than a true implementation of the Python
10+
3 :class:`bytes` object, which is substantially different.
11+
12+
``future`` contains a backport of the :mod:`bytes` object from Python 3
13+
which passes most of the Python 3 tests for :mod:`bytes`. (See
1414
:ref:`bytes-test-results`.) You can use it as follows::
1515

1616
from future.builtins import bytes
1717
1818
b = bytes(b'ABCD')
1919

20-
On Py2, this object inherits from Python 2's native ``str``, but it enforces
21-
the much stricter separation from unicode strings that Python 3's ``bytes``
22-
requires::
20+
On Py2, this object inherits from Python 2's :class:`str`, but it
21+
enforces the much stricter separation from unicode strings that Python
22+
3's :class:`bytes` requires::
2323

2424
>>> b + u'EFGH' # TypeError
2525
Traceback (most recent call last):
@@ -31,16 +31,17 @@ requires::
3131
File "<stdin>", line 1, in <module>
3232
TypeError: sequence item 0: expected bytes, found unicode string
3333

34-
In most other ways, these ``bytes`` objects have identical behaviours to Python 3's ``bytes``::
34+
In most other ways, these :class:`bytes` objects have identical
35+
behaviours to Python 3's :class:`bytes`::
3536

3637
b = bytes(b'ABCD')
3738
assert list(b) == [65, 66, 67, 68]
3839
assert repr(b) == "b'ABCD'"
3940
assert b.split(b'b') == [b'A', b'CD']
4041

41-
Currently the easiest way to ensure identical use of byte-strings compatibly between
42-
Python 3 and 2 is to wrap all byte-string literals ``b'...'`` in a ``bytes()``
43-
call, as follows::
42+
Currently the easiest way to ensure identical use of byte-strings
43+
compatibly between Python 3 and 2 is to wrap all byte-string literals
44+
``b'...'`` in a :func:`~bytes()`` call, as follows::
4445
4546
from future.builtins import *
4647
@@ -50,30 +51,30 @@ call, as follows::
5051

5152
# ...
5253

53-
This is not perfect, but it is superior to manually debugging and fixing code
54-
incompatibilities caused by the many differences between Py3 bytes and Py2
55-
strings.
54+
This is not perfect, but it is superior to manually debugging and fixing
55+
code incompatibilities caused by the many differences between Py3 bytes
56+
and Py2 strings.
5657

5758

5859
.. _bytes-test-results:
5960

6061
Test results
6162
~~~~~~~~~~~~
6263

63-
For reference, when not using the backported ``bytes`` object, running the Py3.3
64-
``bytes`` unit tests in ``test_bytes.py`` on Py2 (after fixing imports) gives
65-
this::
64+
For reference, when not using the backported :class:`bytes` object,
65+
running the Py3.3 ``bytes`` unit tests in ``test_bytes.py`` on Py2 (after
66+
fixing imports) gives this::
6667

6768
--------------------------------------------------------------
6869
Ran 203 tests in 0.209s
6970
7071
FAILED (failures=31, errors=55, skipped=1)
7172
--------------------------------------------------------------
7273

73-
The ``future`` backport of the Py3 ``bytes`` object passes most of the Python 3
74-
tests for ``bytes`` on Py2, except those requiring specific wording in exception
75-
messages.
74+
The ``future`` backport of the Py3 :class:`bytes` object passes most of
75+
the Python 3 tests for ``bytes`` on Py2, except those requiring specific
76+
wording in exception messages.
7677

77-
See ``future/tests/test_bytes.py`` in the source for the unit tests that are
78-
actually run.
78+
See ``future/tests/test_bytes.py`` in the source for the unit tests that
79+
are actually run.
7980

docs/source/faq.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FAQ
2-
***
1+
Frequently Asked Questions (FAQ)
2+
********************************
33

44
Who is this for?
55
================

docs/source/future_imports.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Imports
66
future imports
77
~~~~~~~~~~~~~~
88

9-
The imports to include at the top of every future-compatible Py3/2 module are::
9+
The imports to include at the top of every future-compatible Py3/2
10+
module are::
1011

1112
from __future__ import (absolute_import, division,
1213
print_function, unicode_literals)
@@ -29,8 +30,8 @@ explicit form.)
2930
__future__ imports
3031
~~~~~~~~~~~~~~~~~~
3132

32-
For more information about the ``__future__`` imports, which are a standard
33-
feature of Python, see the following docs:
33+
For more information about the ``__future__`` imports, which are a
34+
standard feature of Python, see the following docs:
3435

3536
- absolute_import: `PEP 328: Imports: Multi-Line and Absolute/Relative <http://www.python.org/dev/peps/pep-0328>`_
3637
- division: `PEP 238: Changing the Division Operator <http://www.python.org/dev/peps/pep-0238>`_

docs/source/index.rst

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
future: clean single-source support for Python 3 and 2
22
======================================================
33

4-
``future`` is the missing compatibility layer between Python 3 and Python 2. It
5-
allows you to maintain a single, clean Python 3.x-compatible codebase with
6-
minimal cruft and also run it on Python 2 without further modification.
4+
``future`` is the missing compatibility layer between Python 3 and
5+
Python 2. It allows you to maintain a single, clean Python
6+
3.x-compatible codebase with minimal cruft and also run it on Python 2
7+
without further modification.
78

89
It is designed to be used together with Python's built-in ``__future__``
910
imports like this::
@@ -17,19 +18,5 @@ followed by standard Python 3 code, which then runs unchanged on both
1718
Python 3 and Python 2.7. For examples, see the :ref:`overview`.
1819

1920

20-
**Features:**
21-
22-
- backports or remappings for 15 builtins with different semantics on Py3 versus Py2
23-
- supports the reorganized Py3 standard library interface
24-
- 220+ unit tests
25-
- clean on Py3: ``future`` imports and decorators have no effect on Py3 (and
26-
no namespace pollution)
27-
- ``futurize`` script for automatic conversion from either Py2 or Py3 to a
28-
clean single-source codebase compatible with both Py3 and Py2
29-
- a consistent set of utility functions and decorators selected from
30-
Py2/3 compatibility interfaces from projects like six, IPython, Jinja2,
31-
Django, and Pandas.
32-
33-
3421
.. include:: contents.rst.inc
3522

docs/source/overview.rst

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,46 @@
33
Overview
44
========
55

6-
``future`` is the missing compatibility layer between Python 3 and Python 2. It
7-
allows you to maintain a single, clean Python 3.x-compatible codebase with
8-
minimal cruft and run it easily on Python 2 without further modification.
6+
``future`` is the missing compatibility layer between Python 3 and Python
7+
2. It allows you to maintain a single, clean Python 3.x-compatible
8+
codebase with minimal cruft and run it easily on Python 2 without further
9+
modification.
910

10-
It is designed to be used together with Python's built-in ``__future__``
11-
imports like this::
11+
.. _features:
12+
13+
**Features:**
14+
15+
- backports or remappings for 15 builtins with different semantics on
16+
Py3 versus Py2
17+
- supports the reorganized Py3 standard library interface
18+
- 220+ unit tests
19+
- clean on Py3: ``future`` imports and decorators have no effect on Py3
20+
(and no namespace pollution)
21+
- ``futurize`` script for automatic conversion from either Py2 or Py3
22+
to a clean single-source codebase compatible with both Py3 and Py2
23+
- a consistent set of utility functions and decorators selected from
24+
Py2/3 compatibility interfaces from projects like six, IPython,
25+
Jinja2, Django, and Pandas.
1226

13-
from __future__ import (absolute_import, division,
14-
print_function, unicode_literals)
15-
from future import standard_library
16-
from future.builtins import *
17-
18-
followed by standard Python 3 code, which then runs unchanged on both
19-
Python 3 and Python 2.7.
2027

2128
.. _code-examples:
2229

2330
Code examples
2431
-------------
2532

26-
After the imports above, this code runs identically on Python 3 and 2::
33+
``future`` is designed to be imported at the top of each Python module
34+
together with Python's built-in ``__future__`` module like this::
35+
36+
from __future__ import (absolute_import, division,
37+
print_function, unicode_literals)
38+
from future import standard_library
39+
from future.builtins import *
40+
41+
followed by standard Python 3 code. The imports allow this code to run
42+
unchanged on Python 3 and Python 2.7.
43+
44+
For example, after these imports, this code runs identically on Python 3
45+
and 2.7::
2746
2847
# Support for renamed standard library modules via import hooks
2948
from http.client import HttpConnection

0 commit comments

Comments
 (0)