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 reference' does not traverse through relative imports

See original GitHub issue

Environment data

  • VS Code version: 1.21.p
  • Extension version (available under the Extensions sidebar): 2018.2.1
  • OS and version: macOS 10.13.3
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.4
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): pipenv with proper python path in vscode
  • Relevant/affected Python packages and their versions: flask_restplus

Actual behavior

Going to definition for Namespace from flask_restplus goes to __init__.py instead of file namespace.py. Also vscode shows error “instance of Namespace has no member …” etc, since vscode-python cannot learn that

from .namespace import ...

is

from namespace import ...

Expected behavior

No errors, going to definition is fine

Steps to reproduce:

  1. Install pipenv, config vscode to work with python version
  2. Install flask_restplus, import Namespace from library, try to go inside and go to definition of Namespace in init.py file
  3. See vscode-python does not recognize “from .namespace import” and does not lead anywhere
  4. Remove dot and repeat
  5. See everything is working fine now, but source has been modified, so it’s not a solution

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

XXX

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
idchlifecommented, Apr 25, 2018

@brettcannon it was my fault actually. I mixed autocompletion with goto definition.

I tried development build and it is indeed fixed! This is fantastic! Thanks!

1reaction
brettcannoncommented, Apr 25, 2018

@idchlife sorry about the misunderstanding! I now understand you wanted to navigate to the module itself and not the object.

But I have good news! Our next release should fix this: example

You can download our development build and try it out yourself if you would like to validate we have fixed this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

beyond top level package error in relative import
The top-level package is test_A in the error case, and the relative import tries to traverse into the parent package directory, starting at...
Read more >
Absolute and Relative Imports in Python - GeeksforGeeks
Relative imports is not so readable as absolute ones. Using relative imports it is not easy because it is very hard to tell...
Read more >
Photo by Lacie Slezak on Unsplash - Medium
Module Specifiers rely on a Module Resolution traversing strategy. ... When using Relative Import References, it is also not necessary for ...
Read more >
How Pros Get Rid of Relative Imports - DEV Community ‍ ‍
Paths · The pathname doesn't have to be the same as the actual folder name. But it's a good idea to keep them...
Read more >
The Definitive Guide to Python import Statements | Chris Yeh
The only acceptable syntax for relative imports is from .[module] import name. All import forms not starting with . are interpreted as absolute ......
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