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.

Go to definition for Python project does not work with relative imports

See original GitHub issue

Environment data

VS Code version: Version 1.18.1 (1.18.1) Python Extension version: 0.8.0 Python Version: 3.6 OS and version: Mac High Sierra

Actual behavior

Assuming my current project structure:

-stopwatch_app
--test.py
--utils
---greeter.py

And contents of:

# test.py

from utils.greeter import print_greeting

def main():
    print_greeting()
# utils/greeter.py

def print_greeting():
   print('Hello')

In test.py, when I select go to definition for the print_greeting method in main (Figure 1), it automatically places the cursor right before the import definition (Figure 2).

Figure 1 image

Figure 2 image

Expected behavior

It should instead take me to the print_greeting() definition in the utils/greeter.py file.

Steps to reproduce:

  • Download the source stopwatch_app.zip
  • Open the source project in VSCode
  • Go to test.py, right click on print_greeting() defined in main and select Go To Definition

Logs

Output from Python output panel
N/A

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:21
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
brettcannoncommented, Apr 19, 2018

Should be fixed in the next release.

4reactions
brettcannoncommented, Dec 4, 2017

@imdadahad there’s no need to bump the issue as we’ve triaged it and are aware of your request. We just also have 57 other issues to verify along with 41 bugs awaiting fixes. 😟

Read more comments on GitHub >

github_iconTop Results From Across the Web

Go to definition for Python project does not work with relative ...
In test.py , when I select go to definition for the print_greeting method in main (Figure 1), it automatically places the cursor right ......
Read more >
Proper relative imports: "Unable to import module"
5 Answers 5 · 1. I have a venv for every project. · I do not use venv. But as per the doco,...
Read more >
Absolute vs Relative Imports in Python
A relative import specifies the resource to be imported relative to the current location—that is, the location where the import statement is. There...
Read more >
Fix Python Relative Imports and Auto-completion in VSCode
In this video, you will learn how to properly handle Python relative imports without extending the sys.path. Additionally, you will learn ...
Read more >
Package Relative Imports - double dot doc example not working
I've been trying to do a double dot import without success, I've tried going back to the official documentation in order to figure...
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