Skip to content

Commit

Permalink
TST: Make pass <3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-Stevens-Haas committed May 6, 2024
1 parent 8f8a973 commit 92f8819
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions doc/release/upcoming_changes/26081.improvement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ This PR also provides the ``np.typing.Array`` type alias in the style of

.. code::
from typing import Literal, TypeVar, TypeVarTuple
from typing import Literal, TypeVar
import numpy as np
import numpy.typing as npt
Expand All @@ -51,14 +51,14 @@ This PR also provides the ``np.typing.Array`` type alias in the style of
arr = np.arange(12, dtype=np.uint16)
stacked = stack_1Ds(arr, arr, arr)
reveal_type(stacked) #
Note that, if shape is unknown or arbitrary, it is still recommended to use
``NDArray``. Because ``TypeVarTuple`` cannot be bound, not all type checkers
allow arbitrarily shape arrays. e.g.:

.. code::
from typing import TypeVarTuple
Shapes = TypeVarTuple("Shapes")
Expand Down
6 changes: 3 additions & 3 deletions numpy/_typing/_add_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ def _parse_docstrings() -> str:
Can be used during runtime for typing arrays with a given dtype
and specified shape. Particularly useful for functions which modify number
of axes. If it is important to enforce integer axis sizes, use np.ndarray
for typing. If axes dimensions are variable, it is best to use
`npt.NDArray <numpy.typing.NDArray>`.
of axes. If it is important to enforce integer axis sizes, use
`np.ndarray <numpy.ndarray>` for typing. If axes dimensions are
variable, it is best to use `npt.NDArray <numpy.typing.NDArray>`.
.. versionadded:: 2.1
Expand Down
4 changes: 4 additions & 0 deletions numpy/typing/tests/data/fail/shape311.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
import numpy as np
import numpy.typing as npt

from typing_extensions import assert_type

if sys.version_info >= (3, 11):
npt.Array[str, str, np.float64] # E: Value of type variable
else:
assert_type(3, str) # still need a reason to fail if < 3.11
4 changes: 2 additions & 2 deletions numpy/typing/tests/data/pass/shape311.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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)
Expand Down

0 comments on commit 92f8819

Please sign in to comment.