Skip to content

Commit dc8c2e6

Browse files
authored
Merge pull request numpy#28995 from jorenham/typing/__future__.annotations
TYP: remove ``from __future__ import annotations``
2 parents c807e09 + 8360da6 commit dc8c2e6

10 files changed

Lines changed: 8 additions & 42 deletions

File tree

numpy/_core/tests/test_arraymethod.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
this is private API, but when added, public API may be added here.
44
"""
55

6-
from __future__ import annotations
7-
86
import types
97
from typing import Any
108

numpy/_core/tests/test_multiarray.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import builtins
42
import collections.abc
53
import ctypes

numpy/_typing/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Private counterpart of ``numpy.typing``."""
22

3-
from __future__ import annotations
4-
53
from ._array_like import ArrayLike as ArrayLike
64
from ._array_like import NDArray as NDArray
75
from ._array_like import _ArrayLike as _ArrayLike

numpy/_typing/_array_like.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import sys
42
from collections.abc import Callable, Collection, Sequence
53
from typing import TYPE_CHECKING, Any, Protocol, TypeAlias, TypeVar, runtime_checkable
@@ -20,7 +18,6 @@
2018

2119
_T = TypeVar("_T")
2220
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
23-
_ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True)
2421
_DTypeT = TypeVar("_DTypeT", bound=dtype[Any])
2522
_DTypeT_co = TypeVar("_DTypeT_co", covariant=True, bound=dtype[Any])
2623

numpy/_typing/_nbit_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class NBitBase:
3030
3131
.. code-block:: python
3232
33-
>>> from __future__ import annotations
3433
>>> from typing import TypeVar, TYPE_CHECKING
3534
>>> import numpy as np
3635
>>> import numpy.typing as npt

numpy/_typing/_nested_sequence.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
"""A module containing the `_NestedSequence` protocol."""
22

3-
from __future__ import annotations
4-
5-
from typing import (
6-
TYPE_CHECKING,
7-
Any,
8-
Protocol,
9-
TypeVar,
10-
runtime_checkable,
11-
)
3+
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, runtime_checkable
124

135
if TYPE_CHECKING:
146
from collections.abc import Iterator
@@ -36,8 +28,6 @@ class _NestedSequence(Protocol[_T_co]):
3628
--------
3729
.. code-block:: python
3830
39-
>>> from __future__ import annotations
40-
4131
>>> from typing import TYPE_CHECKING
4232
>>> import numpy as np
4333
>>> from numpy._typing import _NestedSequence
@@ -64,19 +54,19 @@ def __len__(self, /) -> int:
6454
"""Implement ``len(self)``."""
6555
raise NotImplementedError
6656

67-
def __getitem__(self, index: int, /) -> _T_co | _NestedSequence[_T_co]:
57+
def __getitem__(self, index: int, /) -> "_T_co | _NestedSequence[_T_co]":
6858
"""Implement ``self[x]``."""
6959
raise NotImplementedError
7060

7161
def __contains__(self, x: object, /) -> bool:
7262
"""Implement ``x in self``."""
7363
raise NotImplementedError
7464

75-
def __iter__(self, /) -> Iterator[_T_co | _NestedSequence[_T_co]]:
65+
def __iter__(self, /) -> "Iterator[_T_co | _NestedSequence[_T_co]]":
7666
"""Implement ``iter(self)``."""
7767
raise NotImplementedError
7868

79-
def __reversed__(self, /) -> Iterator[_T_co | _NestedSequence[_T_co]]:
69+
def __reversed__(self, /) -> "Iterator[_T_co | _NestedSequence[_T_co]]":
8070
"""Implement ``reversed(self)``."""
8171
raise NotImplementedError
8272

numpy/f2py/_backends/_backend.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from abc import ABC, abstractmethod
42

53

numpy/f2py/_backends/_meson.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import errno
42
import os
53
import re

numpy/typing/tests/test_runtime.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
"""Test the runtime usage of `numpy.typing`."""
22

3-
from __future__ import annotations
4-
53
from typing import (
64
Any,
75
NamedTuple,
8-
Union,
6+
Union, # pyright: ignore[reportDeprecated]
97
get_args,
108
get_origin,
119
get_type_hints,
@@ -55,10 +53,7 @@ def test_get_type_hints(name: type, tup: TypeTup) -> None:
5553
"""Test `typing.get_type_hints`."""
5654
typ = tup.typ
5755

58-
# Explicitly set `__annotations__` in order to circumvent the
59-
# stringification performed by `from __future__ import annotations`
60-
def func(a): pass
61-
func.__annotations__ = {"a": typ, "return": None}
56+
def func(a: typ) -> None: pass
6257

6358
out = get_type_hints(func)
6459
ref = {"a": typ, "return": type(None)}
@@ -70,10 +65,7 @@ def test_get_type_hints_str(name: type, tup: TypeTup) -> None:
7065
"""Test `typing.get_type_hints` with string-representation of types."""
7166
typ_str, typ = f"npt.{name}", tup.typ
7267

73-
# Explicitly set `__annotations__` in order to circumvent the
74-
# stringification performed by `from __future__ import annotations`
75-
def func(a): pass
76-
func.__annotations__ = {"a": typ_str, "return": None}
68+
def func(a: typ_str) -> None: pass
7769

7870
out = get_type_hints(func)
7971
ref = {"a": typ, "return": type(None)}

numpy/typing/tests/test_typing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import importlib.util
42
import os
53
import re
@@ -118,7 +116,7 @@ def run_mypy() -> None:
118116
filename = None
119117

120118

121-
def get_test_cases(*directories: str) -> Iterator[ParameterSet]:
119+
def get_test_cases(*directories: str) -> "Iterator[ParameterSet]":
122120
for directory in directories:
123121
for root, _, files in os.walk(directory):
124122
for fname in files:

0 commit comments

Comments
 (0)