Skip to content

Commit 86fd829

Browse files
committed
Update docs
1 parent 819c14a commit 86fd829

File tree

7 files changed

+37
-88
lines changed

7 files changed

+37
-88
lines changed

README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,7 @@ into this code which runs on both Py2 and Py3:
205205
name = input()
206206
greet(name)
207207
208-
209-
For complex projects, it may be better to divide the porting into two stages.
210-
``futurize`` supports a ``--stage1`` flag for safe changes that modernize the
211-
code but do not break Python 2.6 compatibility or introduce a depdendency on the
212-
``future`` package. Calling ``futurize --stage2`` then completes the process.
208+
See :ref:`forwards-conversion` and :ref:`backwards-conversion` for more details.
213209

214210

215211
Automatic translation

docs/credits.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Patches
6161
- German Larrain
6262
- Chris Lasher
6363
- Elliott Sales de Andrade
64+
- Tim Shaffer
65+
- Daniel Szoska
6466
- Jeff Tratner
6567
- Mystic-Mirage (GitHub)
6668
- str4d (GitHub)

docs/faq.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,11 @@ most inputs; worse, it allows arbitrary code execution by the user
177177
for specially crafted inputs because of the ``eval()`` executed by Python
178178
2's ``input()`` function.
179179

180-
This is not an isolated example; almost every output of ``2to3`` will
181-
need modification to provide backward compatibility with Python 2.
182-
``future`` is designed for just this purpose.
183-
184-
The ``future`` source tree contains a script called ``futurize`` that is
185-
based on ``lib2to3``. It is designed to turn either Python 2-only or
186-
Python 3-only code into code that is compatible with both platforms.
180+
This is not an isolated example; almost every output of ``2to3`` will need
181+
modification to provide backward compatibility with Python 2. As an
182+
alternative, the ``python-future`` project provides a script called
183+
``futurize`` that is based on ``lib2to3`` but will produce code that is
184+
compatible with both platforms (Py2 and Py3).
187185

188186

189187
Can I maintain a Python 2 codebase and use 2to3 to automatically convert to Python 3 in the setup script?

docs/futurize.rst

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,7 @@
33
Futurize: 2 to both
44
--------------------
55

6-
For example, running ``futurize`` turns this Python 2 code:
7-
8-
.. code-block:: python
9-
10-
import ConfigParser # Py2 module name
11-
12-
class Upper(object):
13-
def __init__(self, iterable):
14-
self._iter = iter(iterable)
15-
def next(self): # Py2-style iterator interface
16-
return next(self._iter).upper()
17-
def __iter__(self):
18-
return self
19-
20-
itr = Upper('hello')
21-
print next(itr),
22-
for letter in itr:
23-
print letter, # Py2-style print statement
24-
25-
into this code which runs on both Py2 and Py3:
26-
27-
.. code-block:: python
28-
29-
from __future__ import print_function
30-
from future import standard_library
31-
standard_library.install_hooks()
32-
from future.builtins import next
33-
from future.builtins import object
34-
import configparser # Py3-style import
35-
36-
class Upper(object):
37-
def __init__(self, iterable):
38-
self._iter = iter(iterable)
39-
def __next__(self): # Py3-style iterator interface
40-
return next(self._iter).upper()
41-
def __iter__(self):
42-
return self
43-
44-
itr = Upper('hello')
45-
print(next(itr), end=' ') # Py3-style print function
46-
for letter in itr:
47-
print(letter, end=' ')
48-
49-
50-
To write out all the changes to your Python files that ``futurize`` suggests,
51-
use the ``-w`` flag.
52-
53-
For complex projects, it is probably best to divide the porting into two stages.
54-
Stage 1 is for "safe" changes that modernize the code but do not break Python
55-
2.6 compatibility or introduce a depdendency on the ``future`` package. Stage 2
56-
is to complete the process.
6+
.. include:: futurize_overview.rst
577

588

599
.. _forwards-conversion-stage1:
@@ -157,16 +107,16 @@ The complete set of fixers applied by ``futurize --stage1`` is:
157107
libfuturize.fixes.fix_raise
158108
159109
160-
Not applied:
110+
The following fixers from ``lib2to3`` are not applied:
161111

162112
.. code-block:: python
163113
164114
lib2to3.fixes.fix_import
165115
166-
The ``fix_absolute_import`` fixer in`` libfuturize.fixes`` is applied instead of
167-
this. The new fixer both makes implicit relative imports explicit and
168-
adds the declaration ``from __future__ import absolute_import`` at the top
169-
of each relevant module.
116+
The ``fix_absolute_import`` fixer in ``libfuturize.fixes`` is applied instead of
117+
``lib2to3.fixes.fix_import``. The new fixer both makes implicit relative
118+
imports explicit and adds the declaration ``from __future__ import
119+
absolute_import`` at the top of each relevant module.
170120

171121
.. code-block:: python
172122
@@ -208,7 +158,7 @@ This converts ``set([1, 2, 3]``) to ``{1, 2, 3}``, breaking Python 2.6 support.
208158
lib2to3.fixes.fix_ws_comma
209159
210160
This performs cosmetic changes. This is not applied by default because it
211-
does not serve improve Python 2/3 compatibility. (In some cases it may
161+
does not serve to improve Python 2/3 compatibility. (In some cases it may
212162
also reduce readability: see issue #58.)
213163

214164

@@ -272,7 +222,7 @@ becomes::
272222
standard_library.install_hooks()
273223
import configparser
274224

275-
A complete list of fixers applied in Stage 2 is::
225+
The complete list of fixers applied in Stage 2 is::
276226

277227
lib2to3.fixes.fix_basestring
278228
lib2to3.fixes.fix_dict
@@ -321,8 +271,7 @@ Not applied::
321271

322272
Fixes applied with the ``futurize --conservative`` option::
323273

324-
libfuturize.fixes.fix_division_safe
325-
(instead of libfuturize.fixes.fix_division).
274+
libfuturize.fixes.fix_division_safe # instead of libfuturize.fixes.fix_division.
326275

327276

328277

docs/quickstart.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ See :ref:`backwards-conversion` for more details.
7777
To convert existing Python 2 code
7878
---------------------------------
7979

80-
Start with this page: :ref:`automatic-conversion`.
80+
.. include:: futurize_overview.rst
81+
82+
See :ref:`forwards-conversion-stage1` and :ref:`forwards-conversion-stage2` for more details.
8183

8284
.. If you already know Python 3, start with the :ref:`automatic-conversion` page.
8385
.. If you don't know Python 3 yet, start with :ref:`python3-essentials`.
@@ -153,6 +155,7 @@ For more information on the automatic translation feature, see :ref:`translation
153155

154156
Next steps
155157
----------
156-
For more information about writing Py2/3-compatible code, see
157-
:ref:`compatible-idioms` and :ref:`what-else`.
158+
For more information about writing Py2/3-compatible code, see:
158159

160+
- :ref:`compatible-idioms`
161+
- :ref:`what-else`.

docs/standard_library_imports.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ modules from Python 3.3 (``future.backports``).
1010

1111
There are currently four interfaces to the reorganized standard library.
1212

13-
1413
Context-manager interface
1514
-------------------------
15+
1616
The recommended interface is via a context-manager called ``hooks``::
1717

18-
from future import standard_library
19-
with standard_library.hooks():
18+
from future.standard_library import hooks
19+
with hooks():
2020
import socketserver
2121
import queue
2222
import configparser
@@ -55,7 +55,7 @@ One workaround is to replace the dot with an underscore::
5555
``import_`` and ``from_import`` functions
5656
-----------------------------------------
5757

58-
A third option, which also works with two-level imports, is to use the
58+
A third interface, which also works with two-level imports, is to use the
5959
``import_`` and ``from_import`` functions from ``future.standard_library`` as
6060
follows::
6161

@@ -117,7 +117,7 @@ modules on Py2::
117117
List of standard library modules
118118
--------------------------------
119119

120-
The modules available from ``future.moves`` via one of the interfaces above are::
120+
The complete list of modules available via one of the four interfaces above is::
121121

122122
import socketserver
123123
import queue
@@ -178,13 +178,11 @@ available independently of the python-future project::
178178
import pathlib # pip install pathlib
179179

180180
A few modules from Python 3.4 and 3.3 are also available in the ``backports``
181-
package namespace::
181+
package namespace after ``pip install backports.lzma`` etc.::
182182

183183
from backports import lzma
184184
from backports import functools_lru_cache as lru_cache
185185

186-
After ``pip install backports.lzma`` etc.
187-
188186
The following Python 2.6 backports of standard library packages from Python 2.7+
189187
are also available::
190188

docs/whatsnew.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
.. _whats-new-0.13.x:
22

3+
What's New
4+
**********
5+
36
What's new in version 0.13.1
4-
****************************
7+
============================
58

69
This is a minor bug-fix release.
710

811
- Fix ``futurize --all-imports`` (issue #101)
912
- Fix ``futurize --output-dir`` logging (issue #102)
1013
- Fix (multiple) inheritance of ``future.builtins.object`` with metaclasses (issues #91 and #96)
1114
- Fix ``futurize``'s refactoring of ``urllib`` imports (issue #94)
12-
- Doc formatting fixes (issues #98, 100)
15+
- Doc formatting fix (issues #98, 100)
1316

1417

15-
What's New in v0.13
16-
*******************
18+
What's new in version 0.13
19+
==========================
1720

1821
This is mostly a clean-up release. It adds some small new compatibility features
1922
and fixes several bugs.
@@ -59,6 +62,6 @@ Bug fixes
5962

6063

6164
Previous versions
62-
-----------------
65+
=================
6366

6467
See the :ref:`whats-old` for versions prior to v0.13.

0 commit comments

Comments
 (0)