jedi-vim icon indicating copy to clipboard operation
jedi-vim copied to clipboard

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

Open kevinkjt2000 opened this issue 3 years ago • 4 comments

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
  • jedi-vim git version: 8763462
  • jedi git submodule status: 8ef2ce232cebf6f30b41b28b2677d84666a97d55 pythonx/jedi (v0.18.0-40-g8ef2ce23)
  • parso git submodule status: ef90bba3b3d4310c345885a1368dbfc8937765a3 pythonx/parso (v0.8.1-1-gef90bba)
Global Python

Using Python version 3 to access Jedi.

  • global sys.executable: /Users/ktindall/.venvs/neovim/bin/python
  • global sys.version: 3.8.7 (default, Feb 19 2021, 09:40:51), [Clang 12.0.0 (clang-1200.0.32.27)]
  • global site module: /Users/ktindall/.asdf/installs/python/3.8.7/lib/python3.8/site.py
Jedi
  • path: /Users/ktindall/.config/nvim/bundle/jedi-vim/pythonx/jedi/jedi/__init__.py
  • version: 0.18.0
Jedi environment: <SameEnvironment: 3.8.7 in /Users/ktindall/.venvs/neovim>
  • executable: /Users/ktindall/.venvs/neovim/bin/python
  • sys_path:
    • /Users/ktindall/.asdf/installs/python/3.8.7/lib/python38.zip
    • /Users/ktindall/.asdf/installs/python/3.8.7/lib/python3.8
    • /Users/ktindall/.asdf/installs/python/3.8.7/lib/python3.8/lib-dynload
    • /Users/ktindall/.venvs/neovim/lib/python3.8/site-packages
Known environments
  • <Environment: 3.9.1 in /Users/ktindall/.asdf/installs/python/3.9.1> (/Users/ktindall/.asdf/installs/python/3.9.1/bin/python3.9)

  • <Environment: 3.8.7 in /Users/ktindall/.asdf/installs/python/3.8.7> (/Users/ktindall/.asdf/installs/python/3.8.7/bin/python3.8)

  • <Environment: 3.7.10 in /Users/ktindall/.asdf/installs/python/3.7.10> (/Users/ktindall/.asdf/installs/python/3.7.10/bin/python3.7)

  • <Environment: 3.6.13 in /Users/ktindall/.asdf/installs/python/3.6.13> (/Users/ktindall/.asdf/installs/python/3.6.13/bin/python3.6)

kevinkjt2000 avatar Jun 01 '21 19:06 kevinkjt2000

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 avatar Jun 01 '21 20:06 blueyed

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?

blueyed avatar Jun 01 '21 20:06 blueyed

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 avatar Jun 02 '21 00:06 kevinkjt2000

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.

kevinkjt2000 avatar Jun 02 '21 02:06 kevinkjt2000