You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, this a known issue. You can currently circumvent it by disabling
the imports fixer.
loewis commented on Nov 25, 2008
loewismannequin
MannequinAuthor
More actions
Are there any plans to improve that? In the specific case, it would help
if commands gets only replaced if an import of commands appears "in
scope" (or, if that is too difficult, anywhere in the file). I think
2to3 should create a list of all names that get imported anywhere, and
compare candidates for renaming against this list.
Also, I tried to work-around by just deleting "commands" from MAPPING
(nobody uses the commands module, anyway); this unfortunately failed
because PATTERN already had the name compiled in. It would be helpful if
PATTERN was computed more lazily, e.g. by overriding compile_pattern.
(I then worked around by regenerating PATTERN after monkey-patching
MAPPING).
but I think this is ok; people just shouldn't write such code in the
first place (and the resulting code does work correctly - just with
a strangely-renamed local variable).
but I think this is ok; people just shouldn't write such code in the
first place (and the resulting code does work correctly - just with
a strangely-renamed local variable).
This also won't work:
deff():
commands.call() # This fails to be fixed.importcommands
Is that reasonable also?
Scoping isn't something that 2to3 does well, and we'd probably have to
add a whole symtable analyzer to fix a few obscure bugs like above.
loewis commented on Nov 26, 2008
loewismannequin
MannequinAuthor
More actions
This is true of many fixers. What is the use case?
In this case, I wanted to work around the fixer working incorrectly
for commands, but still have it continue to work for all the other
modules it fixes. The context is the setup.py script of Django.
Is that reasonable also?
Sure! People will accept that they have to reorganize the source
before 2to3 can work correctly. More precisely, if they follow the
"convert once, cut the bridges" approach, they can just manually
unfix the few places that 2to3 got wrong. If they follow the
"single source" approach, they will accept that they have to
reformulate.
> This is true of many fixers. What is the use case?
In this case, I wanted to work around the fixer working incorrectly
for commands, but still have it continue to work for all the other
modules it fixes. The context is the setup.py script of Django.
I wonder if a better way would be to configure the imports fixer
through the options dict passed to RefactoringTool. i.e.
Activity
loewis commentedon Nov 25, 2008
In 2to3 (from the py3k branch, as of r67372) translates the fragment
to
benjaminp commentedon Nov 25, 2008
Yes, this a known issue. You can currently circumvent it by disabling
the imports fixer.
loewis commentedon Nov 25, 2008
Are there any plans to improve that? In the specific case, it would help
if commands gets only replaced if an import of commands appears "in
scope" (or, if that is too difficult, anywhere in the file). I think
2to3 should create a list of all names that get imported anywhere, and
compare candidates for renaming against this list.
Also, I tried to work-around by just deleting "commands" from MAPPING
(nobody uses the commands module, anyway); this unfortunately failed
because PATTERN already had the name compiled in. It would be helpful if
PATTERN was computed more lazily, e.g. by overriding compile_pattern.
(I then worked around by regenerating PATTERN after monkey-patching
MAPPING).
benjaminp commentedon Nov 25, 2008
This bug certainly has been reported before, so I'll see if I can find
time for it.
benjaminp commentedon Nov 25, 2008
I'm not sure what you mean about MAPPING being compiled in. It is
regenerated every time 2to3 is run.
Anyway, I fixed the replacement problem in r67386.
loewis commentedon Nov 25, 2008
This code does not work:
when followed by an attempt to actually run the fixer. Instead, I need
to write
Thanks! It still transforms
but I think this is ok; people just shouldn't write such code in the
first place (and the resulting code does work correctly - just with
a strangely-renamed local variable).
benjaminp commentedon Nov 25, 2008
On Tue, Nov 25, 2008 at 5:10 PM, Martin v. Löwis <report@bugs.python.org> wrote:
This is true of many fixers. What is the use case?
This also won't work:
Is that reasonable also?
Scoping isn't something that 2to3 does well, and we'd probably have to
add a whole symtable analyzer to fix a few obscure bugs like above.
loewis commentedon Nov 26, 2008
In this case, I wanted to work around the fixer working incorrectly
for commands, but still have it continue to work for all the other
modules it fixes. The context is the setup.py script of Django.
Sure! People will accept that they have to reorganize the source
before 2to3 can work correctly. More precisely, if they follow the
"convert once, cut the bridges" approach, they can just manually
unfix the few places that 2to3 got wrong. If they follow the
"single source" approach, they will accept that they have to
reformulate.
benjaminp commentedon Nov 26, 2008
On Wed, Nov 26, 2008 at 12:45 AM, Martin v. Löwis
<report@bugs.python.org> wrote:
I wonder if a better way would be to configure the imports fixer
through the options dict passed to RefactoringTool. i.e.
loewis commentedon Nov 26, 2008
That's very obscure, IMO. I didn't know that syntax existed, and
I can't guess easily what it means (in general).
In the specific case, it's also difficult to pass the options,
since the distutils command doesn't support doing so.
benjaminp commentedon Nov 26, 2008
Ok. The building of the pattern in fix_imports is changed to
compile_pattern in r67404.