Skip to content

Relative imports broken specifically in __init__.py files #698

@jamesb6626

Description

@jamesb6626

Reproduction is simple. Make two files in the same directory.

foo.py:

def bar():
    "Docstring"
    pass

__init__.py:

from .foo import bar
from . import foo

It is then easily verified, in editing a new line of __init__.py, that the language server will not provide documentation/signature help for bar, either on its own or foo.bar as a member of the relative imported module. Nor will any completion of bar (or any other member of foo) be provided when requested, with the cursor as |, in:

  • from .foo import |
  • foo.|

Both the imports are demonstrated in the example, but either can reproduce the relevant variant of the bug.

A completion of bar alone is available within the example __init__.py when from .foo import bar is present, but the completion erroneously describes it as a module rather than a function. Similarly, foo is completed as a module after from . import foo, but is treated as having no members.

If using e.g. linting with pylint, this still works and recognises bar correctly, for instance bar(1) is identified as having too many positional arguments, so this is completion specific, with completion configured to be provided through this language server by jedi in this case.

This is very strange, as the underlying jedi seems to work fine, through either jedi-vim or jedi-language-server, there is no such issue, so this is python-lsp-server-specific.

This is using python-lsp-server==1.14.0, jedi==0.19.2, on python 3.14.2. Can add more relevant details and configuration if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions