question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rename Refactor does not work for packages with __init__ and PYTHONPATH

See original GitHub issue

Environment data

  • VS Code version: 1.52.1
  • Extension version (available under the Extensions sidebar): 2020.12.424452561
  • OS and version: WIN 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6, 64 bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Relevant/affected Python packages and their versions: rope, latest version
  • Relevant/affected Python-related VS Code extensions and their versions:
  • Value of the python.languageServer setting: Pylance

Expected behaviour

Refactor works in both ways regardess of how module import is implemented.

Actual behaviour

We have a following setup:

  1. Project script(s) on a location A

  2. Packages (internal libraries) on a locations B, C, D, … Each of these packages have its own __init__.py file, where relevant modules are imported. User use these libs as B.<something>, B.<somethingElse>

  3. We have VSC workspace on a location A, but we open it with a batch file, that sets PYTHONPATH so all libs (B, C, D) are available to a project on A.

The problem is that refactoring does not work in both ways, meaning:

  • we can navigate to func definition, for example B.something.func() and refactor it there. This works, all relevant locations in VSC workspace are fixed, including scripts in A that use B.something.func()
  • however, we can’t refactor B.something.func() directly from script from A. VSC just show No results and that is it.

I assume this is not as expected, since, for example, refactorTest.zip

PyCharm seems to handle this scenario somehow.

Steps to reproduce:

  • Open appended workspace via: SET_PYHON_PATH_OPEN_VSC.bat
  • Navigate to proj/app.py -> useLib(). Refactor lib.m1.func1() func1 to whatever. Will fail.
  • Navigate to func1() definition with F12. Refactor it to whatetever, will succeed.

Logs

No log statement is generated. However, GUI pop-up is issued, showing only: No results.

System Info
Item Value
CPUs Intel® Core™ i7-6820HQ CPU @ 2.70GHz (8 x 2712)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.92GB (5.24GB free)
Process Argv –crash-reporter-id 919e0ed9-46f3-4ad4-9e28-f35755bf8266
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
openlogontheside:30221877
python763:30178808
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
python504:30227505
vswsl492:30211401
wsl2prompt:30224612
pythonvsdeb440:30237827
unusedpromptcf:30224611
folderexplorer:30224614
openfilemenu:30224647
pythonvsded773cf:30236630
pythonvspyt859:30237612

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcannoncommented, Dec 23, 2020

@schperplata sorry for the back-and-forth on this. We plan to move to using Jedi for refactoring (#11333) which will then cause us to drop support for Rope (#10440). I will leave this issue open, though, as a reminder of the bug for anyone else who comes across it.

1reaction
brettcannoncommented, Dec 21, 2020

@schperplata actually the absolutely critical bit was what language server you were using which you did not specify.

And while we do appreciate you taking the time to report issues, do also note that our issue volume isn’t small, so we need to be somewhat aggressive in closing issues as the vast majority of people who skip our template never give us the info we need. It’s easier for us to reopen issues for those that do take the time to fill in the info than it is to leave things open and wait for a reply (which is what used to happen to us).

Regardless, Pylance handles refactorings so I am transferring your issue to them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rename Refactor does not work for packages with __ ... - GitHub
We have VSC workspace on a location A, but we open it with a batch file, that sets PYTHONPATH so all libs (B,...
Read more >
Rename and Refactor a Python File in VS Code - Stack Overflow
In VS Code, while I can rename and refactor symbols by highlighting them -> F2, this only works for modules, classes, their members,...
Read more >
Debugging with sys.path / ImportError issues
The theory¶. When you say: from foo.bar import baz ...Python will start by looking for a module named foo, and then inside that...
Read more >
pathlib — Object-oriented filesystem paths — Python 3.11.1 ...
Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >
When Things Go Wrong — PyArmor 7.6.0 documentation
If pyarmor works fine before, but now doesn't work, also make a Clean ... .7/site-packages/pyarmor/pytransform.py INFO Rename it to pytransform/__init__.py ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found