davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.28k stars 370 forks source link

Renaming a named import also includes the import's code. #1057

Closed kevinkjt2000 closed 1 year ago

kevinkjt2000 commented 3 years ago

Issue

Renaming a named import also includes the import's code. I expected that only the file that I'm in, and files that import the symbol that I'm renaming would be affected. Since I'm not sure whether this is an issue with the underlying jedi library or not, I wanted to start here just in case. Please advise if this should be reported directly to jedi instead.

Steps to reproduce

Rename some_alias in the following snippet, and observe that instances of some_library.some_symbol are also renamed.

from some_library import some_symbol as some_alias

Output of “:verbose JediDebugInfo”

Jedi-vim debug information

jedi-vim version
Global Python

Using Python version 3 to access Jedi.

Jedi
Jedi environment: <SameEnvironment: 3.8.7 in /Users/ktindall/.venvs/neovim>
Known environments
blueyed commented 3 years ago

It works for me as expected:

import os
from os import pathsep as some_alias

os.path
os.pathsep
some_alias()

=>

import os
from os import pathsep as asdf

os.path
os.pathsep
asdf()

(using jedi#rename() via mapping)

I might have outdated/different versions - sorry for not having checked/compared that, given that I am not sure if that's the issue after all:

#### Jedi-vim debug information                                                                                                                                                                            

##### jedi-vim version

 - jedi-vim git version: 0.11.0-38-g9e1ae49-dirty
 - jedi git submodule status: +41652507b3de645a8a4329299e8e40bff68c8da7 pythonx/jedi (v0.18.0-63-g41652507)
 - parso git submodule status: +f2b1ff942933a43c34d93e3359e7115d20cc2ee3 pythonx/parso (v0.8.2-10-gf2b1ff9)
blueyed commented 3 years ago

observe that instances of some_library.some_symbol are also renamed.

Please elaborate. Do you mean they are replaced in the some_library module / code?

kevinkjt2000 commented 3 years ago

Yes, exactly that. It was a little confusing that it did not rename some_alias in only the file that I'm in and files that import some_alias.

kevinkjt2000 commented 3 years ago

In my case, there was no other import of the library.

Instead of

import os
from os import pathsep as asdf

only

from os import pathsep as asdf

is present. I don't know if that's important in reproducing this. Also, now that I'm thinking about it, I realize I forgot to mention that I was trying to rename to exactly the same name. e.g. I wanted:

from os import pathsep as pathsep

(I like to clean up non-standard aliases that aren't recommended in a library's documentation) Which is when I was transported to the source code of os.pathsep with modifications present in the buffer.