Skip to content

No completion after import numpy. (possibly related: jedi.auto_import_modules) #704

@xlucn

Description

@xlucn

What does not work

This only happens to numpy imports. If I type

import numpy.
# or
import numpy.polynomial.
# or
from numpy.

there will be no completions.

Environment I have tried

  • Neovim + lspconfig, pylsp installed with mason
  • Vim + vim-lsp, pylsp installed with LspInstallServer
  • Geany + lsp plugin, pylsp installed with pacman

All combinations above behaves the same: no completion. I added no user configurations to these setups.

What I found

There was a issue in jedi repo: davidhalter/jedi#2021.
That issue shows nothing wrong about jedi, but setting jedi.settings.auto_import_modules = ["numpy"] actually causing the lack of completions. Also note davidhalter/jedi#2021 (comment)

if you use jedi.settings.auto_import_modules = ["numpy"], you are actually trying to disable parts of Jedi and this is not expected to work after it.

So I tested

In [6]:
   ...: jedi.settings.auto_import_modules = ["numpy"]

In [7]: script = jedi.Script("from numpy import ")
   ...: print(f"{len(script.complete())=}")
   ...:
   ...: script = jedi.Script("import numpy.")
   ...: print(f"{len(script.complete())=}")
len(script.complete())=534
len(script.complete())=0

In [8]:
   ...: jedi.settings.auto_import_modules = []

In [9]: script = jedi.Script("from numpy import ")
   ...: print(f"{len(script.complete())=}")
   ...:
   ...: script = jedi.Script("import numpy.")
   ...: print(f"{len(script.complete())=}")
len(script.complete())=542
len(script.complete())=33

And I confirm setting the pylsp.plugins.jedi.auto_import_modules option in pylsp's configuration to be empty list will solve this issue.

So, is the default value of pylsp.plugins.jedi.auto_import_modules the root problem? Will there be any side effects after I change it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions