-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On older snakes, was previously assigning Array = NDArray. However, that was causing unexpected errors in testing the shape311.py files. Had to extend numpy.typing.Array to <3.11 using typing_extensions, as well as quoting some type hints in the test files for delayed evaluation. Alternatively, I could have found a way to limit the parameterization of test_fail and test_runs for just >= 3.11. However, IDK how to do that in pytest.
- Loading branch information
1 parent
8f8a973
commit 742153f
Showing
5 changed files
with
34 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import sys | ||
from typing import Literal, NewType, TypeVar, TypeVarTuple | ||
from typing import NewType, TypeVar | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
from typing_extensions import assert_type, cast, reveal_type | ||
from typing_extensions import assert_type | ||
|
||
if sys.version_info >= (3, 11): | ||
DType = TypeVar("DType", bound=np.generic) | ||
# if sys.version_info >= (3, 11): | ||
DType = TypeVar("DType", bound=np.generic) | ||
|
||
# Check that typevartuple in alias is packed correctly | ||
Length = NewType("Length", int) | ||
Width = NewType("Width", int) | ||
arr: npt.Array[Length, Width, np.int8] = np.array([[0]]) | ||
assert_type(arr, np.ndarray[tuple[Length, Width], np.dtype[np.int8]]) | ||
# Check that typevartuple in alias is packed correctly | ||
Length = NewType("Length", int) | ||
Width = NewType("Width", int) | ||
arr: "npt.Array[Length, Width, np.int8]" = np.array([[0]]) | ||
assert_type(arr, np.ndarray[tuple[Length, Width], np.dtype[np.int8]]) | ||
|
||
# Check that typevartuple in alias is unpacked correctly | ||
M = TypeVar("M", bound=int) | ||
N = TypeVar("N", bound=int) | ||
T = TypeVar("T", bound=np.generic) | ||
# Check that typevartuple in alias is unpacked correctly | ||
M = TypeVar("M", bound=int) | ||
N = TypeVar("N", bound=int) | ||
T = TypeVar("T", bound=np.generic) | ||
|
||
|
||
def mult(vec: npt.Array[N, T], mat: npt.Array[M, N, T]) -> npt.Array[M, T]: | ||
return mat @ vec # type: ignore | ||
def mult(vec: "npt.Array[N, T]", mat: "npt.Array[M, N, T]") -> "npt.Array[M, T]": | ||
return mat @ vec # type: ignore | ||
|
||
|
||
arr2: np.ndarray[tuple[Width], np.dtype[np.int8]] = np.array([0]) | ||
assert_type(mult(arr2, arr), np.ndarray[tuple[Length], np.dtype[np.int8]]) | ||
arr2: np.ndarray[tuple[Width], np.dtype[np.int8]] = np.array([0]) | ||
assert_type(mult(arr2, arr), np.ndarray[tuple[Length], np.dtype[np.int8]]) | ||
|
||
|
||
# Check that shape works | ||
def return_shp(a: npt.Array[M, N, DType]) -> tuple[M, N]: | ||
return a.shape | ||
# Check that shape works | ||
def return_shp(a: "npt.Array[M, N, DType]") -> tuple[M, N]: | ||
return a.shape | ||
|
||
shp = return_shp(arr) | ||
assert_type(shp, tuple[Length, Width]) | ||
shp = return_shp(arr) | ||
assert_type(shp, tuple[Length, Width]) |