Lib3to2 began as Google Summer of Code (GSOC) 2009 project by Joe Amenta.
Lib3to2 is a set of fixers and utilities for lib2to3, a source code transformer
included in Python standard library.
Porting from Python 3 to Python 2 codebase is often easier, because there’s
less ambiguity due to stricter rules that Python 3 imposes. Lib3to2 is crucial
in enabling the developer to start enjoying modern Python environment, while
still maintaining compatibility with older runtimes.
If you plan or would like to port your Python 3 code to Python 2 we encourage
you to run 3to2 and report any issues with the transformation. Your experience
with using this library is very valuable in shaping the future goals of this
A great way to influence the project schedule is to use the “It’s affecting me”
and “It’s affecting project” feedback mechanisms.
Run “./3to2” to convert stdin (“-“), files or directories given as
arguments. By default, the tool outputs a unified diff-formatted patch on
standard output and a “what was changed” summary on standard error, but the
“-w” option can be given to write back converted files, creating
“.bak”-named backup files.
- Fix issue with fix_str shadowing fix_bytes (Denis Zawada, #1011581)
- Use temporary value to prevent shadowing function name in decorators
with the same name, e.g. if you use (@property def foo…) and then
(@foo.setter def foo…) (Denis Zawada, #1008074)
- Use entry_points.console_scripts instead of custom script for ‘3to2’
Snapshot of new features and bugfixes.
- fix_kwargs no longer breaks docstrings when adding code to fix parameters.
(Denis Zawada, #880389)
- Format template strings, that use auto-numbered fields, are now converted
to use explicitly numbered fields, thus extending compatibility with
Python 2.6 even further. (Denis Zawada, #881113)
- Chained exceptions (raise E from E) are now included in the __cause__
attribute whenever possible. (Denis Zawada, #881136)
- Function annotations are now collected and set manually. You can access them
via the func_annotations property, exactly like in Python 3.
(Denis Zawada, #881134)
- New fixer fix_funcdecorator, fix_classdecorator equivalent for decorated
functions, is now available and auto-enabled (as a dependency for
fix_annotations) (Denis Zawada)
- __annotations__ attributes are now renamed to func_annotations.
- Attribute renamers with special names (e.g. __nonzero__) are now more
- Method renamers have been DRYed and marked as BM_compatible.
- Some minor issues with preserving whitespace in fix_classdecorator have
been resolved by switching to new implementation, that could be reused.
- Fix_str have been split into fix_str and fix_str_literals. This has allowed
to mark fix_str_literals as BM_compatible and shaved off almost 2 seconds
from the test suite run.
First maintenance release of awkwardduet, a maintenance fork of lib3to2.
The release focus is on fixing major issues reported in lib3to2 1.0 series.
- fix_super now refactors magic super (super() with no arguments) by searching
the parsing tree for class name and the first argument, the same mechanism
used by Python 3 runtime. Until now super() used
of a class name, which caused trouble with non-trivial inheritence.
(Denis Zawada, #880377; originally reported in lib3to2 1.0 series)
- fix_next now correctly parenthesizes generator statements.
(Denis Zawada, #880378)
- fix_next is now aware of extend form of the
next builting, i.e
next(iterable[, default]). If extended signature is detected, a warning is
reported and the code remains unaltered. This provides compatibility with
Python 2.6–7. (Denis Zawada, #880383)
- Python 3 __str__ methods are now converted to __unicode__ in Python 2,
while __bytes__ are converted to __str__. This further extends unicode
compatibility between runtimes. (Denis Zawada, #880382)
- Python 3 default absolute import behavior is now enforced in Python 2.5–7
using the ‘from __future__ import __absolute_import__’ directive.
(Denis Zawada, #880388)
- Testing infrastructure is now compatible with nose runner. (Denis Zawada)
Less recent changes can be found in the NEWS.rst file in the top-level
source code directory.