Skip to content

VSCode's Pylance reports errors when using generics #61

@krokosik

Description

@krokosik

Describe the bug

VSCode's Pylance reports errors when trying to use the example from the package docs. When using the generic function type syntax: TArray: Array, we get type errors on numpy arrays:

Argument of type "NDArray[Any]" cannot be assigned to parameter "x" of type "TArray@generic" in function "generic"
  Type "NDArray[Any]" is not assignable to type "Array[Unknown, Unknown]"
    "ndarray[_Shape, dtype[Any]]" is incompatible with protocol "Array[Unknown, Unknown]"
      "Array[TDtype@Array, TDevice@Array]" is not assignable to "ndarray[_Shape, dtype[Any]]"
      "Array[TDtype@Array, TDevice@Array]" is not assignable to "ndarray[_Shape, dtype[Any]]"
      "Array[TDtype@Array, TDevice@Array]" is not assignable to "ndarray[_Shape, dtype[Any]]"
      "Array[TDtype@Array, TDevice@Array]" is not assignable to "ndarray[_Shape, dtype[Any]]"
      "Array[TDtype@Array, TDevice@Array]" is not assignable to "ndarray[_Shape, dtype[Any]]"
      "Array[TDtype@Array, TDevice@Array]" is not assignable to "ndarray[_Shape, dtype[Any]]"
  ...Pylance[reportArgumentType](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportArgumentType.md)

To Reproduce

  1. Open VSCode
  2. Insert this code and observe Pylance error:
import numpy as np
from array_api._2024_12 import Array

def generic[TArray: Array](x: TArray) -> TArray:
    return x + 1

b = generic(np.array([1, 2, 3]))

Additional context

No response

Version

1.1.4

Platform

Windows 11

Code of Conduct

  • I agree to follow this project's Code of Conduct.

No Duplicate

  • I have checked existing issues to avoid duplicates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions