Skip to content
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

Too many type arguments provided for "NDArray[float64]", when slicing a NumPy array #2161

Closed
jk000 opened this issue Dec 10, 2021 · 3 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@jk000
Copy link

jk000 commented Dec 10, 2021

Example program:

import numpy as np
import numpy.typing as npt

def foo(bar: npt.NDArray[np.float64]):
    bar[1,2]

In v2021.12.1, this produces as error
Too many type arguments provided for "NDArray[float64]"; expected 1 but received 2 with a red squiggle under the "2" in bar[1,2].

However, Pylance version v2021.12.0 does not show this as an error, as is expected.

Environment data

  • Language Server version: 2021.12.1
  • OS and version: win32 x64
  • Python version 3.19.0

Logs

Python Language Server Log

[Info  - 4:33:03 PM] Pylance language server 2021.12.1 (pyright fcab8004) starting
[Info  - 4:33:03 PM] Server root directory: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist
[Info  - 4:33:03 PM] No configuration file found.
[Info  - 4:33:03 PM] No pyproject.toml file found.
[Info  - 4:33:03 PM] Setting pythonPath for service "optimizer": "C:\Users\**********\AppData\Local\Programs\Python\Python310\python.exe"
[Warn  - 4:33:03 PM] stubPath c:\Users\**********\repos\optimizer\typings is not a valid directory.
[Info  - 4:33:03 PM] Assuming Python version 3.10
[Info  - 4:33:03 PM] Assuming Python platform Windows
Search paths for c:\Users\**********\repos\optimizer
  c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib
  c:\Users\**********\repos\optimizer
  c:\Users\**********\repos\optimizer\typings
  c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stubs\...
  c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\bundled\stubs
  c:\Users\**********\AppData\Local\Programs\Python\Python310\DLLs
  c:\Users\**********\AppData\Local\Programs\Python\Python310\Lib
  c:\Users\**********\AppData\Local\Programs\Python\Python310
  c:\Users\**********\AppData\Local\Programs\Python\Python310\Lib\site-packages
[Info  - 4:33:03 PM] Searching for source files
[Info  - 4:33:03 PM] Found 22 source files
[Info  - 4:33:03 PM] Background analysis(1) root directory: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist
[Info  - 4:33:03 PM] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setImportResolver
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: analyze
Background analysis message: setFileOpened
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
[FG] parsing: c:\Users\**********\repos\****path*****\test_file.py (21ms)
[FG] parsing: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 5ms] (87ms)
[FG] binding: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\builtins.pyi (47ms)
[FG] binding: c:\Users\**********\repos\****path*****\test_file.py (0ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens full
[BG(1)] getSemanticTokens full at c:\Users\**********\repos\****path*****\test_file.py ...
[BG(1)]   parsing: c:\Users\**********\repos\****path*****\test_file.py (21ms)
[BG(1)]   parsing: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 2ms] (80ms)
[BG(1)]   binding: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\builtins.pyi (36ms)
[BG(1)]   binding: c:\Users\**********\repos\****path*****\test_file.py (0ms)
[BG(1)]   parsing: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\typing.pyi [fs read 1ms] (24ms)
[BG(1)]   binding: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\typing.pyi (8ms)
[BG(1)]   parsing: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 0ms] (7ms)
[BG(1)]   binding: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (2ms)
[BG(1)]   parsing: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\types.pyi [fs read 0ms] (9ms)
[BG(1)]   binding: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\types.pyi (3ms)
[BG(1)]   parsing: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 0ms] (2ms)
[BG(1)]   binding: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi (2ms)
[BG(1)]   parsing: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\abc.pyi [fs read 0ms] (1ms)
[BG(1)]   binding: c:\Users\**********\.vscode\extensions\ms-python.vscode-pylance-2021.12.1\dist\typeshed-fallback\stdlib\abc.pyi (0ms)
[BG(1)]   parsing: c:\Users\**********\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\__init__.pyi [fs read 0ms] (118ms)
[BG(1)]   binding: c:\Users\**********\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\__init__.pyi (31ms)
[BG(1)]   parsing: c:\Users\**********\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\typing\__init__.py [fs read 0ms] (13ms)
[BG(1)]   binding: c:\Users\**********\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\typing\__init__.py (1ms)
[BG(1)]   parsing: c:\Users\**********\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\typing\_generic_alias.py [fs read 1ms] (6ms)
[BG(1)]   binding: c:\Users\**********\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\typing\_generic_alias.py (4ms)
[BG(1)] getSemanticTokens full at c:\Users\**********\repos\****path*****\test_file.py (406ms)
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 0:0 - 5:0 at c:\Users\**********\repos\****path*****\test_file.py (1ms)
Background analysis message: analyze
[BG(1)] analyzing: c:\Users\**********\repos\****path*****\test_file.py ...
[BG(1)]   checking: c:\Users\**********\repos\****path*****\test_file.py (3ms)
[BG(1)] analyzing: c:\Users\**********\repos\****path*****\test_file.py (3ms)
Background analysis message: resumeAnalysis
Background analysis message: markFilesDirty
Background analysis message: analyze
@christian-cahig
Copy link

Just updated Pylance and I'm having this issue as well.

@erictraut
Copy link
Contributor

Thanks for the bug report. This was unfortunately a regression. It has already been fixed, and the fix will be included in the next release. In the meantime, you can revert back to the previous version of Pylance if this is getting in your way.

Another workaround is to replace the use of the NDArray type alias with its corresponding type. In other words, replace npt.NDArray[np.float64] with np.ndarray[Any, np.dtype[np.float64]].

Apologies for any inconvenience.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Dec 11, 2021
@bschnurr
Copy link
Member

This issue has been fixed in version 2021.12.2, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

4 participants