diff options
author | Bas van Beek <43369155+BvB93@users.noreply.github.com> | 2021-12-21 23:41:09 +0100 |
---|---|---|
committer | Bas van Beek <43369155+BvB93@users.noreply.github.com> | 2021-12-23 21:15:00 +0100 |
commit | fe361df62b101a27fd2ea203fb0b79b6a5f61401 (patch) | |
tree | b4b8c0387ea22d4d70e83f318dd306cd75a782a5 | |
parent | 7b5f39b5eeac583f822741eaf95a8229f2b5f8d7 (diff) | |
download | numpy-fe361df62b101a27fd2ea203fb0b79b6a5f61401.tar.gz |
STY: Use subscriptable `collections.abc` types over the generic aliases in …
43 files changed, 70 insertions, 83 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index c41bed873..ee99ffb36 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -167,26 +167,25 @@ from numpy.typing._extended_precision import ( complex512 as complex512, ) -from typing import ( - Literal as L, - Any, - ByteString, +from collections.abc import ( Callable, Container, - Callable, - Generic, - IO, Iterable, Iterator, Mapping, - NoReturn, - overload, Sequence, Sized, +) +from typing import ( + Literal as L, + Any, + Generic, + IO, + NoReturn, + overload, SupportsComplex, SupportsFloat, SupportsInt, - Text, TypeVar, Union, Protocol, diff --git a/numpy/_pytesttester.pyi b/numpy/_pytesttester.pyi index 383f2616d..67ac87b33 100644 --- a/numpy/_pytesttester.pyi +++ b/numpy/_pytesttester.pyi @@ -1,4 +1,5 @@ -from typing import Iterable, Literal as L +from collections.abc import Iterable +from typing import Literal as L __all__: list[str] diff --git a/numpy/core/_asarray.pyi b/numpy/core/_asarray.pyi index 477b59c7d..0da2de912 100644 --- a/numpy/core/_asarray.pyi +++ b/numpy/core/_asarray.pyi @@ -1,4 +1,5 @@ -from typing import TypeVar, Union, Iterable, overload, Literal +from collections.abc import Iterable +from typing import TypeVar, Union, overload, Literal from numpy import ndarray from numpy.typing import ArrayLike, DTypeLike diff --git a/numpy/core/_ufunc_config.pyi b/numpy/core/_ufunc_config.pyi index 1688221a9..b7c2ebefc 100644 --- a/numpy/core/_ufunc_config.pyi +++ b/numpy/core/_ufunc_config.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Any, Literal, TypedDict +from collections.abc import Callable +from typing import Any, Literal, TypedDict from numpy import _SupportsWrite diff --git a/numpy/core/arrayprint.pyi b/numpy/core/arrayprint.pyi index acbec84e4..996d4c782 100644 --- a/numpy/core/arrayprint.pyi +++ b/numpy/core/arrayprint.pyi @@ -1,5 +1,6 @@ from types import TracebackType -from typing import Any, Callable, Literal, TypedDict, SupportsIndex +from collections.abc import Callable +from typing import Any, Literal, TypedDict, SupportsIndex # Using a private class is by no means ideal, but it is simply a consequence # of a `contextlib.context` returning an instance of aforementioned class diff --git a/numpy/core/einsumfunc.pyi b/numpy/core/einsumfunc.pyi index 24c6d3228..278fa2044 100644 --- a/numpy/core/einsumfunc.pyi +++ b/numpy/core/einsumfunc.pyi @@ -1,4 +1,5 @@ -from typing import TypeVar, Any, overload, Union, Sequence, Literal +from collections.abc import Sequence +from typing import TypeVar, Any, overload, Union, Literal from numpy import ( ndarray, diff --git a/numpy/core/fromnumeric.pyi b/numpy/core/fromnumeric.pyi index 591f9b3c0..472c4ded5 100644 --- a/numpy/core/fromnumeric.pyi +++ b/numpy/core/fromnumeric.pyi @@ -1,5 +1,6 @@ import datetime as dt -from typing import Union, Sequence, Any, overload, TypeVar, Literal +from collections.abc import Sequence +from typing import Union, Any, overload, TypeVar, Literal from numpy import ( ndarray, diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi index b8816bd26..e06220dc3 100644 --- a/numpy/core/multiarray.pyi +++ b/numpy/core/multiarray.pyi @@ -2,15 +2,13 @@ import os import datetime as dt +from collections.abc import Sequence, Callable, Iterable from typing import ( Literal as L, Any, - Callable, - Iterable, overload, TypeVar, Union, - Sequence, SupportsIndex, final, Final, diff --git a/numpy/core/numeric.pyi b/numpy/core/numeric.pyi index a8727b1ce..8b92abab4 100644 --- a/numpy/core/numeric.pyi +++ b/numpy/core/numeric.pyi @@ -1,8 +1,7 @@ +from collections.abc import Callable, Sequence from typing import ( Any, Union, - Sequence, - Callable, overload, TypeVar, Literal, diff --git a/numpy/core/numerictypes.pyi b/numpy/core/numerictypes.pyi index 1ad7dc7ce..f8c49b957 100644 --- a/numpy/core/numerictypes.pyi +++ b/numpy/core/numerictypes.pyi @@ -1,12 +1,12 @@ import sys import types +from collections.abc import Iterable from typing import ( Literal as L, Union, overload, Any, TypeVar, - Iterable, Protocol, TypedDict, ) diff --git a/numpy/core/records.pyi b/numpy/core/records.pyi index 1e837b492..4eee93d87 100644 --- a/numpy/core/records.pyi +++ b/numpy/core/records.pyi @@ -1,9 +1,8 @@ import os +from collections.abc import Sequence, Iterable from typing import ( - Sequence, Any, TypeVar, - Iterable, overload, Protocol, ) diff --git a/numpy/core/shape_base.pyi b/numpy/core/shape_base.pyi index f0f0f6f56..63cbd773c 100644 --- a/numpy/core/shape_base.pyi +++ b/numpy/core/shape_base.pyi @@ -1,4 +1,5 @@ -from typing import TypeVar, overload, Sequence, Any, SupportsIndex +from collections.abc import Sequence +from typing import TypeVar, overload, Any, SupportsIndex from numpy import generic, dtype from numpy.typing import ArrayLike, NDArray, _FiniteNestedSequence, _SupportsArray diff --git a/numpy/ctypeslib.pyi b/numpy/ctypeslib.pyi index 892d4b7e2..106356873 100644 --- a/numpy/ctypeslib.pyi +++ b/numpy/ctypeslib.pyi @@ -5,6 +5,7 @@ from ctypes import c_int64 as _c_intp import os import sys import ctypes +from collections.abc import Iterable, Sequence from typing import ( Literal as L, Any, @@ -12,9 +13,7 @@ from typing import ( TypeVar, Generic, overload, - Iterable, ClassVar, - Sequence, ) from numpy import ( diff --git a/numpy/f2py/__init__.pyi b/numpy/f2py/__init__.pyi index af5a49328..6e3a82cf8 100644 --- a/numpy/f2py/__init__.pyi +++ b/numpy/f2py/__init__.pyi @@ -1,6 +1,7 @@ import os import subprocess -from typing import Literal as L, Any, Iterable, overload, TypedDict +from collections.abc import Iterable +from typing import Literal as L, Any, overload, TypedDict from numpy._pytesttester import PytestTester diff --git a/numpy/fft/_pocketfft.pyi b/numpy/fft/_pocketfft.pyi index a04fff402..fa234fc3a 100644 --- a/numpy/fft/_pocketfft.pyi +++ b/numpy/fft/_pocketfft.pyi @@ -1,7 +1,5 @@ -from typing import ( - Literal as L, - Sequence, -) +from collections.abc import Sequence +from typing import Literal as L from numpy import complex128, float64 from numpy.typing import ArrayLike, NDArray, _ArrayLikeNumber_co diff --git a/numpy/lib/arrayterator.pyi b/numpy/lib/arrayterator.pyi index 71fc1b6d7..b32dffdfc 100644 --- a/numpy/lib/arrayterator.pyi +++ b/numpy/lib/arrayterator.pyi @@ -1,7 +1,7 @@ +from collections.abc import Generator from typing import ( Any, TypeVar, - Generator, Union, overload, ) diff --git a/numpy/lib/function_base.pyi b/numpy/lib/function_base.pyi index 157ee783d..6e2f886cf 100644 --- a/numpy/lib/function_base.pyi +++ b/numpy/lib/function_base.pyi @@ -1,16 +1,13 @@ import sys +from collections.abc import Sequence, Iterator, Callable, Iterable from typing import ( Literal as L, - Sequence, Union, Any, TypeVar, - Iterator, overload, - Callable, Protocol, SupportsIndex, - Iterable, SupportsInt, ) diff --git a/numpy/lib/histograms.pyi b/numpy/lib/histograms.pyi index a809bc905..81f26d910 100644 --- a/numpy/lib/histograms.pyi +++ b/numpy/lib/histograms.pyi @@ -1,8 +1,8 @@ +from collections.abc import Sequence from typing import ( Literal as L, Any, SupportsIndex, - Sequence, ) from numpy.typing import ( diff --git a/numpy/lib/index_tricks.pyi b/numpy/lib/index_tricks.pyi index 1e6aa6968..923cb8a9f 100644 --- a/numpy/lib/index_tricks.pyi +++ b/numpy/lib/index_tricks.pyi @@ -1,9 +1,9 @@ +from collections.abc import Sequence from typing import ( Any, TypeVar, Generic, overload, - Sequence, Literal, SupportsIndex, ) diff --git a/numpy/lib/npyio.pyi b/numpy/lib/npyio.pyi index 326358c13..60684c846 100644 --- a/numpy/lib/npyio.pyi +++ b/numpy/lib/npyio.pyi @@ -2,22 +2,17 @@ import os import sys import zipfile import types +from re import Pattern +from collections.abc import Collection, Mapping, Iterator, Sequence, Callable, Iterable from typing import ( - Collection, Literal as L, Any, - Mapping, TypeVar, Generic, - Iterator, Union, IO, overload, - Sequence, - Callable, - Pattern, Protocol, - Iterable, ) from numpy import ( diff --git a/numpy/lib/shape_base.pyi b/numpy/lib/shape_base.pyi index b659481ce..82702e67c 100644 --- a/numpy/lib/shape_base.pyi +++ b/numpy/lib/shape_base.pyi @@ -1,4 +1,5 @@ -from typing import TypeVar, Callable, Sequence, Any, overload, SupportsIndex, Protocol +from collections.abc import Callable, Sequence +from typing import TypeVar, Any, overload, SupportsIndex, Protocol from numpy import ( generic, diff --git a/numpy/lib/stride_tricks.pyi b/numpy/lib/stride_tricks.pyi index 5f6e30726..e05a9f74c 100644 --- a/numpy/lib/stride_tricks.pyi +++ b/numpy/lib/stride_tricks.pyi @@ -1,4 +1,5 @@ -from typing import Any, Iterable, TypeVar, overload, SupportsIndex +from collections.abc import Iterable +from typing import Any, TypeVar, overload, SupportsIndex from numpy import dtype, generic from numpy.typing import ( diff --git a/numpy/lib/twodim_base.pyi b/numpy/lib/twodim_base.pyi index 626682bdb..76d7e5a9d 100644 --- a/numpy/lib/twodim_base.pyi +++ b/numpy/lib/twodim_base.pyi @@ -1,7 +1,6 @@ +from collections.abc import Callable, Sequence from typing import ( Any, - Callable, - Sequence, overload, TypeVar, Union, diff --git a/numpy/lib/type_check.pyi b/numpy/lib/type_check.pyi index 5fba3a7f5..72eb777be 100644 --- a/numpy/lib/type_check.pyi +++ b/numpy/lib/type_check.pyi @@ -1,8 +1,7 @@ +from collections.abc import Container, Iterable from typing import ( Literal as L, Any, - Container, - Iterable, overload, TypeVar, Protocol, diff --git a/numpy/lib/utils.pyi b/numpy/lib/utils.pyi index 5bde8e620..407ce1120 100644 --- a/numpy/lib/utils.pyi +++ b/numpy/lib/utils.pyi @@ -1,10 +1,8 @@ from ast import AST +from collections.abc import Callable, Mapping, Sequence from typing import ( Any, - Callable, - Mapping, overload, - Sequence, TypeVar, Protocol, ) diff --git a/numpy/linalg/__init__.pyi b/numpy/linalg/__init__.pyi index eef773af2..d9acd5581 100644 --- a/numpy/linalg/__init__.pyi +++ b/numpy/linalg/__init__.pyi @@ -1,5 +1,3 @@ -from typing import Any - from numpy.linalg.linalg import ( matrix_power as matrix_power, solve as solve, diff --git a/numpy/linalg/linalg.pyi b/numpy/linalg/linalg.pyi index ca7958e61..ae0d4fe12 100644 --- a/numpy/linalg/linalg.pyi +++ b/numpy/linalg/linalg.pyi @@ -1,6 +1,6 @@ +from collections.abc import Iterable from typing import ( Literal as L, - Iterable, overload, TypeVar, Any, diff --git a/numpy/ma/__init__.pyi b/numpy/ma/__init__.pyi index 377c63569..04368b6c4 100644 --- a/numpy/ma/__init__.pyi +++ b/numpy/ma/__init__.pyi @@ -1,5 +1,3 @@ -from typing import Any - from numpy._pytesttester import PytestTester from numpy.ma import extras as extras diff --git a/numpy/ma/core.pyi b/numpy/ma/core.pyi index ff769a8d4..ffdb21983 100644 --- a/numpy/ma/core.pyi +++ b/numpy/ma/core.pyi @@ -1,4 +1,5 @@ -from typing import Any, TypeVar, Callable +from collections.abc import Callable +from typing import Any, TypeVar from numpy import ndarray, dtype, float64 from numpy import ( diff --git a/numpy/matrixlib/defmatrix.pyi b/numpy/matrixlib/defmatrix.pyi index 91c7fa81d..8358bb111 100644 --- a/numpy/matrixlib/defmatrix.pyi +++ b/numpy/matrixlib/defmatrix.pyi @@ -1,4 +1,5 @@ -from typing import Any, Sequence, Mapping +from collections.abc import Sequence, Mapping +from typing import Any from numpy import matrix as matrix from numpy.typing import ArrayLike, DTypeLike, NDArray diff --git a/numpy/random/_generator.pyi b/numpy/random/_generator.pyi index ebfc6a770..bac25ffd5 100644 --- a/numpy/random/_generator.pyi +++ b/numpy/random/_generator.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, Union, overload, TypeVar, Literal +from collections.abc import Callable +from typing import Any, Union, overload, TypeVar, Literal from numpy import ( bool_, diff --git a/numpy/random/bit_generator.pyi b/numpy/random/bit_generator.pyi index d6dac98e6..c5f976d07 100644 --- a/numpy/random/bit_generator.pyi +++ b/numpy/random/bit_generator.pyi @@ -1,11 +1,9 @@ import abc from threading import Lock +from collections.abc import Callable, Mapping, Sequence from typing import ( Any, - Callable, - Mapping, NamedTuple, - Sequence, TypedDict, TypeVar, Union, diff --git a/numpy/random/mtrand.pyi b/numpy/random/mtrand.pyi index d9ecb80f9..5af449add 100644 --- a/numpy/random/mtrand.pyi +++ b/numpy/random/mtrand.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, Union, overload, Literal +from collections.abc import Callable +from typing import Any, Union, overload, Literal from numpy import ( bool_, diff --git a/numpy/testing/_private/utils.pyi b/numpy/testing/_private/utils.pyi index ab3e6f805..8117f18ae 100644 --- a/numpy/testing/_private/utils.pyi +++ b/numpy/testing/_private/utils.pyi @@ -5,17 +5,15 @@ import types import warnings import unittest import contextlib +from re import Pattern +from collections.abc import Callable, Iterable, Sequence from typing import ( Literal as L, Any, AnyStr, - Callable, ClassVar, - Iterable, NoReturn, overload, - Pattern, - Sequence, type_check_only, TypeVar, Union, diff --git a/numpy/typing/_generic_alias.py b/numpy/typing/_generic_alias.py index 9579b22a4..0541ad77f 100644 --- a/numpy/typing/_generic_alias.py +++ b/numpy/typing/_generic_alias.py @@ -2,12 +2,10 @@ from __future__ import annotations import sys import types +from collections.abc import Generator, Iterable, Iterator from typing import ( Any, ClassVar, - Generator, - Iterable, - Iterator, NoReturn, TypeVar, TYPE_CHECKING, diff --git a/numpy/typing/tests/data/fail/arrayprint.pyi b/numpy/typing/tests/data/fail/arrayprint.pyi index 86297a0b2..71b921e3a 100644 --- a/numpy/typing/tests/data/fail/arrayprint.pyi +++ b/numpy/typing/tests/data/fail/arrayprint.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Any +from collections.abc import Callable +from typing import Any import numpy as np AR: np.ndarray diff --git a/numpy/typing/tests/data/pass/literal.py b/numpy/typing/tests/data/pass/literal.py index ad74b417d..d06431eed 100644 --- a/numpy/typing/tests/data/pass/literal.py +++ b/numpy/typing/tests/data/pass/literal.py @@ -1,7 +1,7 @@ from __future__ import annotations from functools import partial -from typing import Callable +from collections.abc import Callable import pytest # type: ignore import numpy as np diff --git a/numpy/typing/tests/data/pass/simple.py b/numpy/typing/tests/data/pass/simple.py index 85965e0de..03ca3e83f 100644 --- a/numpy/typing/tests/data/pass/simple.py +++ b/numpy/typing/tests/data/pass/simple.py @@ -2,7 +2,7 @@ import operator import numpy as np -from typing import Iterable # noqa: F401 +from collections.abc import Iterable # Basic checks array = np.array([1, 2]) diff --git a/numpy/typing/tests/data/reveal/arrayprint.pyi b/numpy/typing/tests/data/reveal/arrayprint.pyi index e797097eb..6e65a8d8a 100644 --- a/numpy/typing/tests/data/reveal/arrayprint.pyi +++ b/numpy/typing/tests/data/reveal/arrayprint.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import numpy as np AR: np.ndarray[Any, Any] diff --git a/numpy/typing/tests/data/reveal/char.pyi b/numpy/typing/tests/data/reveal/char.pyi index ce8c1b269..0563b3472 100644 --- a/numpy/typing/tests/data/reveal/char.pyi +++ b/numpy/typing/tests/data/reveal/char.pyi @@ -1,6 +1,6 @@ import numpy as np import numpy.typing as npt -from typing import Sequence +from collections.abc import Sequence AR_U: npt.NDArray[np.str_] AR_S: npt.NDArray[np.bytes_] diff --git a/numpy/typing/tests/data/reveal/nested_sequence.pyi b/numpy/typing/tests/data/reveal/nested_sequence.pyi index 771bd54bb..c9f91cfa2 100644 --- a/numpy/typing/tests/data/reveal/nested_sequence.pyi +++ b/numpy/typing/tests/data/reveal/nested_sequence.pyi @@ -1,4 +1,5 @@ -from typing import Sequence, Any +from collections.abc import Sequence +from typing import Any import numpy.typing as npt a: Sequence[int] diff --git a/numpy/typing/tests/data/reveal/testing.pyi b/numpy/typing/tests/data/reveal/testing.pyi index 9813dc723..fb419d48d 100644 --- a/numpy/typing/tests/data/reveal/testing.pyi +++ b/numpy/typing/tests/data/reveal/testing.pyi @@ -2,7 +2,8 @@ from __future__ import annotations import re import sys -from typing import Any, Callable, TypeVar +from collections.abc import Callable +from typing import Any, TypeVar from pathlib import Path import numpy as np diff --git a/numpy/typing/tests/test_generic_alias.py b/numpy/typing/tests/test_generic_alias.py index af6eb8b36..8df2eea93 100644 --- a/numpy/typing/tests/test_generic_alias.py +++ b/numpy/typing/tests/test_generic_alias.py @@ -5,8 +5,7 @@ import copy import types import pickle import weakref -from collections.abc import Callable -from typing import TypeVar, Any, Union +from typing import TypeVar, Any, Union, Callable import pytest import numpy as np |