1. Joe Amenta
  2. lib3to2
  3. Issues
Issue #7 wontfix

3to2 doesn't track builtins bound to other names

Joe Amenta
repo owner created an issue

The following (and things like it) don't get refactored as it should:

{{{ some_name = print some_name('a', 'b', 'c', sep='d', end='e') }}}

Comments (4)

  1. Joe Amenta reporter

    Closing this one as "wontfix". Short reason: it's really hard, it wouldn't work, and it's not important enough.

    Long reason: Syntactically, there's no bulletproof way to handle this. Names can become bound in a variety of different ways. When a name is bound in the module-global scope within that same module, then lib3to2 has a chance of finding something like the assignment statement in the bug description and fixing it. However, if another module imports some_name from this module, lib3to2 would have no information that some_name refers to the builtin print function and would leave it alone. exec() can also bind names.

    The current implementation of lib3to2 makes similar trade-offs, and I have come to accept that this tool's place is as an aid throughout the development of backwards-compatible Python code, rather than a tool to take an existing Python 3 codebase and turn it into a Python 2 codebase like 2to3 does (in the opposite direction, of course). There are some amazing hoops that I've made lib3to2 jump through, but in the end, there are limitations of both the lib2to3 framework and the nature of Python 3 that limit lib3to2's potential.

    This particular bug is outside of the lib2to3 framework's capabilities, and my efforts would be better directed towards other deficiencies of lib3to2 than lib2to3's limitations.

  2. Log in to comment