-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autocompletion not working for numpy >= 1.22 #1864
Comments
The issue seems to be with numpy's new typing feature. For np.typing.NDArray jedi crashes in jedi/jedi/inference/gradual/stub_value.py Lines 88 to 89 in 7ff0d2d
because name.get_definition() returns None .
For me, a simple guard like this if definition is not None:
if definition.type in ('import_from', 'import_name'):
... fixes the issue. As I am not very much familiar with the codebase, I do not know if NDArray should even end up down this path, maybe this is just the symptom of another underlying issue. I do have 2 failed tests with this applied, but they are the same failed tests as without the fix. |
How is |
This is the definition from the current numpy master branch, which should be numpy version 1.23.1. |
Changes: * The `test_numpy_completion` test is currently broken - see davidhalter/jedi#1864 * The test flags were moved from setup.cfg to pyproject.toml - see python-lsp/python-lsp-server#207 * A dependency on `whatthepatch` was added for yapf - see python-lsp/python-lsp-server#136
The direct cause for this is the last line of
Type stubs are currently parsed using python 3.7 grammar: Lines 123 to 130 in 6c9cab2
jedi/jedi/inference/__init__.py Lines 194 to 195 in 6c9cab2
jedi/jedi/inference/__init__.py Line 93 in 6c9cab2
jedi ignores the syntax errors, and thinks NDArray[Any]: ... is some sort of setitem definition, but StubFilter._is_name_reachable() calls get_definition() without include_setitem=True and it returns None . Bumping the grammar version up to 3.8 fixes the issue.
|
Feel free to PR this. Thanks a lot for the investigation. I feel like we should just use the 3.10 or 3.11 grammar there instead of 3.8 though. Ideally you would add tests, but I would even merge without that. |
I just increased the stub parsing version. So this should now be fixed. But please test this, I was not able to reproduce the issue with Numpy 1.23. |
Yes, applying that fix to v0.18.1 works. I was only able to reproduce it on master if I reverted #1870.
|
Jedi v0.18.1 autocompletion seems to be broken for the numpy versions since Python 3.10 support.
Minimal reproducible example with numpy==1.23.0:
The text was updated successfully, but these errors were encountered: