Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Slicker can't distinguish variable names from function names. #38

Open
csilvers opened this issue Feb 11, 2019 · 1 comment
Open

Slicker can't distinguish variable names from function names. #38

csilvers opened this issue Feb 11, 2019 · 1 comment

Comments

@csilvers
Copy link
Member

Suppose you have this file:

def foo(): ...
def bar():
    foos = ...
    for foo in foos: ...

and then you do slicker oldfile.foo newfile.py to move foo to newfile.py. The result is this:

def bar():
    foos = ...
    for newfile.foo in foos: ...

which obviously is not correct.

The problem is that a variable is shadowing a function name, so while slicker thinks it's renaming a reference to the function it's actually renaming a reference to the variable.

I think that we could actually do a pretty good job with this, without too much trouble. The idea would be to see to find all places the symbol-to-rewrite is used in an assignment context (in this case "for foo in"), and go up the AST to the function that happens in, and don't do any renaming in that function. But I may be missing something that makes this too hacky to be useful in general.

@benjaminjkraft
Copy link
Contributor

This is an example of #19, but I'll leave it open since it has a clearer example. I think it's not hard to do, but it requires actually tracking scopes rather than traversing the AST without much context as we do now. It's not hacky: we're just following the same algorithm python does to figure out name shadowing. But I suspect it's a decent bit of work to refactor such that it's possible.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants