[issue10070] 2to3 wishes for already-2to3'ed files

Martin v. Löwis report at bugs.python.org
Tue Oct 12 19:24:02 CEST 2010


Martin v. Löwis <martin at v.loewis.de> added the comment:

> How about this phrasing: “Make 2to3 fixers not touch code in a block
> starting with ’if sys.version >= '3'’“ (and hexversion, version_info,
> you get the idea)?

I don't think this can work. You may have to write code like

if sys.version_info >= (3,):
  try:
    some_code()
  except Exception, e:
    pass

(i.e. not use the "as" syntax), because it otherwise won't parse on
Python 2. Hence, one has to rely on 2to3 fixing it, even though
it will never be run on Python 2.

So any scheme of skipping code must be opt-in.

While I now understand what is being requested, I still fail to see
the rationale. In my applications of 2to3, I never look at the generated
code, so it doesn't bother me at all if print gets another pairs of
brackets, or if redundant (but dead) import statements are inserted.

In fact, I also avoid writing code explicitly so that it works
unmodified on Python 3 if I know that 2to3 will fix it.

There has been a long-standing request to suppress 2to3 in certain
expressions in cases where the 2to3 conversion would actually be
incorrect. However, this does not seem to be the motivation here.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10070>
_______________________________________


More information about the Python-bugs-list mailing list