Skip to content

Commit 5c37673

Browse files
authored
Improve how Jedi handles Numpy (#281)
1 parent de937ea commit 5c37673

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

Diff for: CONFIGURATION.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This server can be configured using the `workspace/didChangeConfiguration` metho
1616
| `pylsp.plugins.flake8.indentSize` | `integer` | Set indentation spaces. | `null` |
1717
| `pylsp.plugins.flake8.perFileIgnores` | `array` of `string` items | A pairing of filenames and violation codes that defines which violations to ignore in a particular file, for example: `["file_path.py:W305,W304"]`). | `[]` |
1818
| `pylsp.plugins.flake8.select` | `array` of unique `string` items | List of errors and warnings to enable. | `null` |
19+
| `pylsp.plugins.jedi.auto_import_modules` | `array` of `string` items | List of module names for jedi.settings.auto_import_modules. | `["numpy"]` |
1920
| `pylsp.plugins.jedi.extra_paths` | `array` of `string` items | Define extra paths for jedi.Script. | `[]` |
2021
| `pylsp.plugins.jedi.env_vars` | `object` | Define environment variables for jedi.Script and Jedi.names. | `null` |
2122
| `pylsp.plugins.jedi.environment` | `string` | Define environment for jedi.Script and Jedi.names. | `null` |

Diff for: pylsp/config/schema.json

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@
8787
"uniqueItems": true,
8888
"description": "List of errors and warnings to enable."
8989
},
90+
"pylsp.plugins.jedi.auto_import_modules": {
91+
"type": "array",
92+
"default": ["numpy"],
93+
"items": {
94+
"type": "string"
95+
},
96+
"description": "List of module names for jedi.settings.auto_import_modules."
97+
},
9098
"pylsp.plugins.jedi.extra_paths": {
9199
"type": "array",
92100
"default": [],

Diff for: pylsp/workspace.py

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
log = logging.getLogger(__name__)
1616

17+
DEFAULT_AUTO_IMPORT_MODULES = ["numpy"]
18+
1719
# TODO: this is not the best e.g. we capture numbers
1820
RE_START_WORD = re.compile('[A-Za-z_0-9]*$')
1921
RE_END_WORD = re.compile('^[A-Za-z_0-9]*')
@@ -252,6 +254,8 @@ def jedi_script(self, position=None, use_document_path=False):
252254

253255
if self._config:
254256
jedi_settings = self._config.plugin_settings('jedi', document_path=self.path)
257+
jedi.settings.auto_import_modules = jedi_settings.get('auto_import_modules',
258+
DEFAULT_AUTO_IMPORT_MODULES)
255259
environment_path = jedi_settings.get('environment')
256260
extra_paths = jedi_settings.get('extra_paths') or []
257261
env_vars = jedi_settings.get('env_vars')

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test = [
5353
"pytest",
5454
"pytest-cov",
5555
"coverage",
56-
"numpy<1.23",
56+
"numpy",
5757
"pandas",
5858
"matplotlib",
5959
"pyqt5",

0 commit comments

Comments
 (0)