Skip to content

Commit d0e3c69

Browse files
committed
Add list of fixers used to docs (issue #58)
1 parent a999675 commit d0e3c69

File tree

1 file changed

+101
-6
lines changed

1 file changed

+101
-6
lines changed

docs/futurize.rst

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Futurize: 2 to both
44
--------------------
55

66
For example, running ``futurize`` turns this Python 2 code::
7-
7+
88
import ConfigParser # Py2 module name
99

1010
class Upper(object):
@@ -21,7 +21,7 @@ For example, running ``futurize`` turns this Python 2 code::
2121
print letter, # Py2-style print statement
2222

2323
into this code which runs on both Py2 and Py3::
24-
24+
2525
from __future__ import print_function
2626
from future import standard_library
2727
standard_library.install_hooks()
@@ -145,20 +145,61 @@ The complete set of fixers applied by ``futurize --stage1`` is::
145145
lib2to3.fixes.fix_ws_comma
146146
lib2to3.fixes.fix_xreadlines
147147
libfuturize.fixes.fix_absolute_import
148-
libfuturize.fixes.fix_division
149148
libfuturize.fixes.fix_print_with_import
150149
libfuturize.fixes.fix_raise
151150
libfuturize.fixes.fix_order___future__imports
152151

153152

153+
Not applied:
154+
155+
.. code-block:: python
156+
157+
lib2to3.fixes.fix_import
158+
159+
The ``fix_absolute_import`` fixer in`` libfuturize.fixes`` is applied instead of
160+
this. The new fixer both makes implicit relative imports explicit and
161+
adds the declaration ``from __future__ import absolute_import`` at the top
162+
of each relevant module.
163+
164+
.. code-block:: python
165+
166+
lib2to3.fixes.fix_print
167+
168+
The ``fix_print_with_import`` fixer in ``libfuturize.fixes`` changes the code to
169+
use print as a function and also adds ``from __future__ import
170+
print_function`` to the top of modules using ``print()``.
171+
172+
.. code-block:: python
173+
174+
lib2to3.fixes.fix_raise
175+
176+
This fixer translates code to use the Python 3-only ``with_traceback()``
177+
method on exceptions.
178+
179+
.. code-block:: python
180+
181+
lib2to3.fixes.fix_set_literal
182+
183+
This converts ``set([1, 2, 3]``) to ``{1, 2, 3}``, breaking Python 2.6 support.
184+
185+
.. code-block:: python
186+
187+
lib2to3.fixes.fix_ws_comma
188+
189+
This performs cosmetic changes. This is not applied by default because it
190+
does not serve improve Python 2/3 compatibility. (In some cases it may
191+
also reduce readability: see issue #58.)
192+
193+
194+
154195
.. _forwards-conversion-stage2:
155196

156197
Stage 2: Py3-style code with ``future`` wrappers for Py2
157198
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158199

159200
Run stage 2 of the conversion process with::
160201

161-
futurize -stage2 myfolder/*.py
202+
futurize --stage2 myfolder/*.py
162203

163204
This stage adds a dependency on the ``future`` package. The goal for stage 2 is
164205
to make further mostly safe changes to the Python 2 code to use Python 3-style
@@ -205,11 +246,65 @@ For example::
205246
import ConfigParser
206247

207248
becomes::
208-
249+
209250
from future import standard_library
210251
standard_library.install_hooks()
211252
import configparser
212253

254+
A complete list of fixers applied in Stage 2 is::
255+
256+
lib2to3.fixes.fix_basestring
257+
lib2to3.fixes.fix_dict
258+
lib2to3.fixes.fix_exec
259+
lib2to3.fixes.fix_getcwdu
260+
lib2to3.fixes.fix_input
261+
lib2to3.fixes.fix_itertools
262+
lib2to3.fixes.fix_itertools_imports
263+
lib2to3.fixes.fix_filter
264+
lib2to3.fixes.fix_long
265+
lib2to3.fixes.fix_map
266+
lib2to3.fixes.fix_nonzero
267+
lib2to3.fixes.fix_operator
268+
lib2to3.fixes.fix_raw_input
269+
lib2to3.fixes.fix_zip
270+
271+
libfuturize.fixes.fix_cmp
272+
libfuturize.fixes.fix_division
273+
libfuturize.fixes.fix_execfile
274+
libfuturize.fixes.fix_future_builtins
275+
libfuturize.fixes.fix_future_standard_library
276+
libfuturize.fixes.fix_future_standard_library_urllib
277+
libfuturize.fixes.fix_metaclass
278+
libpasteurize.fixes.fix_newstyle
279+
libfuturize.fixes.fix_object
280+
libfuturize.fixes.fix_order___future__imports
281+
libfuturize.fixes.fix_unicode_keep_u
282+
libfuturize.fixes.fix_xrange_with_import
283+
284+
285+
Not applied::
286+
287+
lib2to3.fixes.fix_buffer # Perhaps not safe. Test this.
288+
lib2to3.fixes.fix_callable # Not needed in Py3.2+
289+
lib2to3.fixes.fix_execfile # Some problems: see issue #37.
290+
# We use the custom libfuturize.fixes.fix_execfile instead.
291+
lib2to3.fixes.fix_future # Removing __future__ imports is bad for Py2 compatibility!
292+
lib2to3.fixes.fix_imports # Called by libfuturize.fixes.fix_future_standard_library
293+
lib2to3.fixes.fix_imports2 # We don't handle this yet (dbm)
294+
lib2to3.fixes.fix_metaclass # Causes SyntaxError in Py2! Use the one from ``six`` instead
295+
lib2to3.fixes.fix_unicode # Strips off the u'' prefix, which removes a potentially
296+
# helpful source of information for disambiguating
297+
# unicode/byte strings.
298+
lib2to3.fixes.fix_urllib # Included in libfuturize.fix_future_standard_library_urllib
299+
lib2to3.fixes.fix_xrange # Custom one because of a bug with Py3.3's lib2to3
300+
301+
302+
Fixes applied with the ``futurize --conservative`` option::
303+
304+
libfuturize.fixes.fix_division_safe
305+
(instead of libfuturize.fixes.fix_division).
306+
307+
213308

214309
.. Ideally the output of this stage should not be a ``SyntaxError`` on either
215310
.. Python 3 or Python 2.
@@ -225,7 +320,7 @@ string literals with either ``b`` or ``u`` accordingly. Furthermore, to ensure
225320
that these types behave similarly on Python 2 as on Python 3, also wrap
226321
byte-strings or text in the ``bytes`` and ``str`` types from ``future``. For
227322
example::
228-
323+
229324
from future.builtins import bytes, str
230325
b = bytes(b'\x00ABCD')
231326
s = str(u'This is normal text')

0 commit comments

Comments
 (0)