Skip to content

Relative import 'Go to definition' is wrong when the folder matches an upstream folder #2450

Closed

Description

Environment data

  • VS Code version: 1.26.1
  • Extension version (available under the Extensions sidebar): 2018.7.1
  • OS and version: macOS High Sierra 10.13.6
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7.10
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv
  • Relevant/affected Python packages and their versions: N/A

Actual behavior

'Go to definition' looks in the wrong path when the file's folder matches the name of an upstream folder. For example, relative imports for api/whatever/api_test1.py resolves to whatever/ not api/whatever.

Expected behavior

'Go to definition' looks in the current directory for imports.

Steps to reproduce:

Open a new workspace with the following directory structure:

api/
    __init__.py
    whatever/
        __init__.py
        api_test1.py
        api_test2.py
whatever/
    __init__.py
    test1.py
    test2.py
__init__.py
  1. Open api_test1.py.
  2. Type from .
  3. Observe that it autocompletes with test1.py and test2.py instead of the expected api_test2.py.
  4. Add a function to api_test2.py and observe that after importing from .api_test2.py import my_func, 'Go to definition' does not work
  5. Add a function to test1.py and observe that after importing from .test1.py import my_func, 'Go to definition' opens test1.my_func, which is incorrect

vscoderelativeimports

Logs

No errors in Output or Developer Tools consoles

Activity

  1. brettcannon commented on Aug 29, 2018

    @brettcannon
    Member

    I've reported this bug upstream to Jedi. Here are the example files for easier testing:
    example.zip

  2. tejajrk commented on Feb 26, 2019

    @tejajrk

    I am still facing this issue. Is it fixed?

  3. brettcannon commented on Feb 27, 2019

    @brettcannon
    Member

    tejajrk please check the upstream issue that is referenced in the issue.

  4. brettcannon commented on Jul 29, 2019

    @brettcannon
    Member

    Closing as this is an upstream issue which we don't have direct control or influence over.

  5. locked as resolved and limited conversation to collaborators on Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions