Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1646138f
Commit
1646138f
authored
May 21, 2010
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update 2to3 docs
parent
7ff5a27b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
Doc/library/2to3.rst
Doc/library/2to3.rst
+14
-5
No files found.
Doc/library/2to3.rst
View file @
1646138f
...
...
@@ -86,13 +86,21 @@ document could also be refactored with this option.
The :option:`-v` option enables output of more information on the translation
process.
Since some print statements can be parsed as function calls or statements, 2to3
cannot always read files containing the print function. When 2to3 detects the
presence of the ``from __future__ import print_function`` compiler directive, it
modifies its internal grammar to interpert :func:`print` as a function. This
change can also be enabled manually with the :option:`-p` flag. Use
:option:`-p` to run fixers on code that already has had its print statements
converted.
.. _2to3-fixers:
Fixers
------
Each step of tranforming code is encapsulated in a fixer. The command ``2to3
Each step of tran
s
forming code is encapsulated in a fixer. The command ``2to3
-l`` lists them. As :ref:`documented above <2to3-using>`, each can be turned on
and off individually. They are described here in more detail.
...
...
@@ -114,7 +122,8 @@ and off individually. They are described here in more detail.
.. 2to3fixer:: callable
Converts ``callable(x)`` to ``hasattr(x, "__call__")``.
Converts ``callable(x)`` to ``isinstance(x, collections.Callable)``, adding
an import to :mod:`collections` if needed.
.. 2to3fixer:: dict
...
...
@@ -167,11 +176,11 @@ and off individually. They are described here in more detail.
.. 2to3fixer:: idioms
This optional fixer p
re
forms several transformations that make Python code
more idiomatic. Type comparis
i
ons like ``type(x) is SomeClass`` and
This optional fixer p
er
forms several transformations that make Python code
more idiomatic. Type comparisons like ``type(x) is SomeClass`` and
``type(x) == SomeClass`` are converted to ``isinstance(x, SomeClass)``.
``while 1`` becomes ``while True``. This fixer also tries to make use of
:func:`sorted` in appropiate places. For example, this block ::
:func:`sorted` in approp
r
iate places. For example, this block ::
L = list(some_iterable)
L.sort()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment