From 6f6e862b308ade0a8397c0f970ac6ae413022955 Mon Sep 17 00:00:00 2001 From: nstarman Date: Mon, 11 Sep 2023 23:40:14 -0400 Subject: [PATCH] Move `__all__` to PEP-8 recommended location Module level "dunders" (i.e. names with two leading and two trailing underscores) such as __all__, __author__, __version__, etc. should be placed after the module docstring but before any import statements except from __future__ imports. Python mandates that future-imports must appear in the module before any other code except docstrings. Signed-off-by: nstarman --- src/array_api_stubs/__init__.py | 1 - src/array_api_stubs/_draft/_types.py | 47 ++++--- src/array_api_stubs/_draft/array_object.py | 4 +- src/array_api_stubs/_draft/constants.py | 4 +- .../_draft/creation_functions.py | 40 +++--- .../_draft/data_type_functions.py | 6 +- src/array_api_stubs/_draft/data_types.py | 6 +- .../_draft/elementwise_functions.py | 126 +++++++++--------- src/array_api_stubs/_draft/fft.py | 35 +++-- .../_draft/indexing_functions.py | 5 +- src/array_api_stubs/_draft/linalg.py | 54 ++++---- .../_draft/linear_algebra_functions.py | 6 +- .../_draft/manipulation_functions.py | 30 ++--- .../_draft/searching_functions.py | 6 +- src/array_api_stubs/_draft/set_functions.py | 6 +- .../_draft/sorting_functions.py | 6 +- .../_draft/statistical_functions.py | 6 +- .../_draft/utility_functions.py | 6 +- 18 files changed, 197 insertions(+), 197 deletions(-) diff --git a/src/array_api_stubs/__init__.py b/src/array_api_stubs/__init__.py index b3c7f1976..4ac3783ef 100644 --- a/src/array_api_stubs/__init__.py +++ b/src/array_api_stubs/__init__.py @@ -1,2 +1 @@ from . import _2021_12, _2022_12, _draft - diff --git a/src/array_api_stubs/_draft/_types.py b/src/array_api_stubs/_draft/_types.py index 589606784..2a73dda24 100644 --- a/src/array_api_stubs/_draft/_types.py +++ b/src/array_api_stubs/_draft/_types.py @@ -6,6 +6,27 @@ """ from __future__ import annotations +__all__ = [ + "Any", + "List", + "Literal", + "NestedSequence", + "Optional", + "PyCapsule", + "SupportsBufferProtocol", + "SupportsDLPack", + "Tuple", + "Union", + "Sequence", + "array", + "device", + "dtype", + "ellipsis", + "finfo_object", + "iinfo_object", + "Enum", +] + from dataclasses import dataclass from typing import ( Any, @@ -34,6 +55,7 @@ @dataclass class finfo_object: """Dataclass returned by `finfo`.""" + bits: int eps: float max: float @@ -41,14 +63,17 @@ class finfo_object: smallest_normal: float dtype: dtype + @dataclass class iinfo_object: """Dataclass returned by `iinfo`.""" + bits: int max: int min: int dtype: dtype + _T_co = TypeVar("_T_co", covariant=True) @@ -58,25 +83,3 @@ def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]: def __len__(self, /) -> int: ... - - -__all__ = [ - "Any", - "List", - "Literal", - "NestedSequence", - "Optional", - "PyCapsule", - "SupportsBufferProtocol", - "SupportsDLPack", - "Tuple", - "Union", - "Sequence", - "array", - "device", - "dtype", - "ellipsis", - "finfo_object", - "iinfo_object", - "Enum", -] diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index cf6adcf3c..e5d34248c 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -1,5 +1,7 @@ from __future__ import annotations +__all__ = ["array"] + from ._types import ( array, dtype as Dtype, @@ -1059,5 +1061,3 @@ def to_device( array = _array - -__all__ = ["array"] diff --git a/src/array_api_stubs/_draft/constants.py b/src/array_api_stubs/_draft/constants.py index c7aaddc5e..c5735d09f 100644 --- a/src/array_api_stubs/_draft/constants.py +++ b/src/array_api_stubs/_draft/constants.py @@ -1,3 +1,5 @@ +__all__ = ["e", "inf", "nan", "newaxis", "pi"] + e = 2.718281828459045 """ IEEE 754 floating-point representation of Euler's constant. @@ -26,5 +28,3 @@ ``pi = 3.1415926535897932384626433...`` """ - -__all__ = ["e", "inf", "nan", "newaxis", "pi"] diff --git a/src/array_api_stubs/_draft/creation_functions.py b/src/array_api_stubs/_draft/creation_functions.py index 42d6f9420..5e2bb44e6 100644 --- a/src/array_api_stubs/_draft/creation_functions.py +++ b/src/array_api_stubs/_draft/creation_functions.py @@ -1,3 +1,23 @@ +__all__ = [ + "arange", + "asarray", + "empty", + "empty_like", + "eye", + "from_dlpack", + "full", + "full_like", + "linspace", + "meshgrid", + "ones", + "ones_like", + "tril", + "triu", + "zeros", + "zeros_like", +] + + from ._types import ( List, NestedSequence, @@ -563,23 +583,3 @@ def zeros_like( out: array an array having the same shape as ``x`` and filled with zeros. """ - - -__all__ = [ - "arange", - "asarray", - "empty", - "empty_like", - "eye", - "from_dlpack", - "full", - "full_like", - "linspace", - "meshgrid", - "ones", - "ones_like", - "tril", - "triu", - "zeros", - "zeros_like", -] diff --git a/src/array_api_stubs/_draft/data_type_functions.py b/src/array_api_stubs/_draft/data_type_functions.py index 700bffd90..a5e9895b2 100644 --- a/src/array_api_stubs/_draft/data_type_functions.py +++ b/src/array_api_stubs/_draft/data_type_functions.py @@ -1,3 +1,6 @@ +__all__ = ["astype", "can_cast", "finfo", "iinfo", "isdtype", "result_type"] + + from ._types import Union, Tuple, array, dtype, finfo_object, iinfo_object @@ -208,6 +211,3 @@ def result_type(*arrays_and_dtypes: Union[array, dtype]) -> dtype: out: dtype the dtype resulting from an operation involving the input arrays and dtypes. """ - - -__all__ = ["astype", "can_cast", "finfo", "iinfo", "isdtype", "result_type"] diff --git a/src/array_api_stubs/_draft/data_types.py b/src/array_api_stubs/_draft/data_types.py index 614807414..d15f4a9f7 100644 --- a/src/array_api_stubs/_draft/data_types.py +++ b/src/array_api_stubs/_draft/data_types.py @@ -1,3 +1,6 @@ +__all__ = ["__eq__"] + + from ._types import dtype @@ -17,6 +20,3 @@ def __eq__(self: dtype, other: dtype, /) -> bool: out: bool a boolean indicating whether the data type objects are equal. """ - - -__all__ = ["__eq__"] diff --git a/src/array_api_stubs/_draft/elementwise_functions.py b/src/array_api_stubs/_draft/elementwise_functions.py index 5f474e7c8..147eff9cd 100644 --- a/src/array_api_stubs/_draft/elementwise_functions.py +++ b/src/array_api_stubs/_draft/elementwise_functions.py @@ -1,3 +1,66 @@ +__all__ = [ + "abs", + "acos", + "acosh", + "add", + "asin", + "asinh", + "atan", + "atan2", + "atanh", + "bitwise_and", + "bitwise_left_shift", + "bitwise_invert", + "bitwise_or", + "bitwise_right_shift", + "bitwise_xor", + "ceil", + "conj", + "cos", + "cosh", + "divide", + "equal", + "exp", + "expm1", + "floor", + "floor_divide", + "greater", + "greater_equal", + "imag", + "isfinite", + "isinf", + "isnan", + "less", + "less_equal", + "log", + "log1p", + "log2", + "log10", + "logaddexp", + "logical_and", + "logical_not", + "logical_or", + "logical_xor", + "multiply", + "negative", + "not_equal", + "positive", + "pow", + "real", + "remainder", + "round", + "sign", + "sin", + "sinh", + "square", + "sqrt", + "subtract", + "tan", + "tanh", + "trunc", +] + + from ._types import array @@ -2477,66 +2540,3 @@ def trunc(x: array, /) -> array: - If ``x_i`` is ``-0``, the result is ``-0``. - If ``x_i`` is ``NaN``, the result is ``NaN``. """ - - -__all__ = [ - "abs", - "acos", - "acosh", - "add", - "asin", - "asinh", - "atan", - "atan2", - "atanh", - "bitwise_and", - "bitwise_left_shift", - "bitwise_invert", - "bitwise_or", - "bitwise_right_shift", - "bitwise_xor", - "ceil", - "conj", - "cos", - "cosh", - "divide", - "equal", - "exp", - "expm1", - "floor", - "floor_divide", - "greater", - "greater_equal", - "imag", - "isfinite", - "isinf", - "isnan", - "less", - "less_equal", - "log", - "log1p", - "log2", - "log10", - "logaddexp", - "logical_and", - "logical_not", - "logical_or", - "logical_xor", - "multiply", - "negative", - "not_equal", - "positive", - "pow", - "real", - "remainder", - "round", - "sign", - "sin", - "sinh", - "square", - "sqrt", - "subtract", - "tan", - "tanh", - "trunc", -] diff --git a/src/array_api_stubs/_draft/fft.py b/src/array_api_stubs/_draft/fft.py index 7979095fe..4a59392d5 100644 --- a/src/array_api_stubs/_draft/fft.py +++ b/src/array_api_stubs/_draft/fft.py @@ -1,3 +1,20 @@ +__all__ = [ + "fft", + "ifft", + "fftn", + "ifftn", + "rfft", + "irfft", + "rfftn", + "irfftn", + "hfft", + "ihfft", + "fftfreq", + "rfftfreq", + "fftshift", + "ifftshift", +] + from ._types import Tuple, Union, Sequence, array, Optional, Literal, device @@ -651,21 +668,3 @@ def ifftshift(x: array, /, *, axes: Union[int, Sequence[int]] = None) -> array: .. versionadded:: 2022.12 """ - - -__all__ = [ - "fft", - "ifft", - "fftn", - "ifftn", - "rfft", - "irfft", - "rfftn", - "irfftn", - "hfft", - "ihfft", - "fftfreq", - "rfftfreq", - "fftshift", - "ifftshift", -] diff --git a/src/array_api_stubs/_draft/indexing_functions.py b/src/array_api_stubs/_draft/indexing_functions.py index 3b218fdac..3f4c25215 100644 --- a/src/array_api_stubs/_draft/indexing_functions.py +++ b/src/array_api_stubs/_draft/indexing_functions.py @@ -1,3 +1,5 @@ +__all__ = ["take"] + from ._types import Union, Optional, array @@ -29,6 +31,3 @@ def take(x: array, indices: array, /, *, axis: Optional[int] = None) -> array: .. versionadded:: 2022.12 """ - - -__all__ = ["take"] diff --git a/src/array_api_stubs/_draft/linalg.py b/src/array_api_stubs/_draft/linalg.py index 29dd6849f..dc74cd239 100644 --- a/src/array_api_stubs/_draft/linalg.py +++ b/src/array_api_stubs/_draft/linalg.py @@ -1,3 +1,30 @@ +__all__ = [ + "cholesky", + "cross", + "det", + "diagonal", + "eigh", + "eigvalsh", + "inv", + "matmul", + "matrix_norm", + "matrix_power", + "matrix_rank", + "matrix_transpose", + "outer", + "pinv", + "qr", + "slogdet", + "solve", + "svd", + "svdvals", + "tensordot", + "trace", + "vecdot", + "vector_norm", +] + + from ._types import Literal, Optional, Tuple, Union, Sequence, array, dtype from .constants import inf @@ -822,30 +849,3 @@ def vector_norm( .. versionchanged:: 2022.12 Added complex data type support. """ - - -__all__ = [ - "cholesky", - "cross", - "det", - "diagonal", - "eigh", - "eigvalsh", - "inv", - "matmul", - "matrix_norm", - "matrix_power", - "matrix_rank", - "matrix_transpose", - "outer", - "pinv", - "qr", - "slogdet", - "solve", - "svd", - "svdvals", - "tensordot", - "trace", - "vecdot", - "vector_norm", -] diff --git a/src/array_api_stubs/_draft/linear_algebra_functions.py b/src/array_api_stubs/_draft/linear_algebra_functions.py index d9ac2437c..a6f84e392 100644 --- a/src/array_api_stubs/_draft/linear_algebra_functions.py +++ b/src/array_api_stubs/_draft/linear_algebra_functions.py @@ -1,3 +1,6 @@ +__all__ = ["matmul", "matrix_transpose", "tensordot", "vecdot"] + + from ._types import Tuple, Union, Sequence, array @@ -155,6 +158,3 @@ def vecdot(x1: array, x2: array, /, *, axis: int = -1) -> array: - if the size of the axis over which to compute the dot product is not the same (before broadcasting) for both ``x1`` and ``x2``. """ - - -__all__ = ["matmul", "matrix_transpose", "tensordot", "vecdot"] diff --git a/src/array_api_stubs/_draft/manipulation_functions.py b/src/array_api_stubs/_draft/manipulation_functions.py index d62cd4f07..74b62a689 100644 --- a/src/array_api_stubs/_draft/manipulation_functions.py +++ b/src/array_api_stubs/_draft/manipulation_functions.py @@ -1,3 +1,18 @@ +__all__ = [ + "broadcast_arrays", + "broadcast_to", + "concat", + "expand_dims", + "flip", + "permute_dims", + "reshape", + "roll", + "squeeze", + "stack", + "unstack", +] + + from ._types import List, Optional, Tuple, Union, array @@ -232,18 +247,3 @@ def unstack(x: array, /, *, axis: int = 0) -> Tuple[array, ...]: out: Tuple[array, ...] tuple of slices along the given dimension. All the arrays have the same shape. """ - - -__all__ = [ - "broadcast_arrays", - "broadcast_to", - "concat", - "expand_dims", - "flip", - "permute_dims", - "reshape", - "roll", - "squeeze", - "stack", - "unstack", -] diff --git a/src/array_api_stubs/_draft/searching_functions.py b/src/array_api_stubs/_draft/searching_functions.py index 9dcc0f95c..e586a7656 100644 --- a/src/array_api_stubs/_draft/searching_functions.py +++ b/src/array_api_stubs/_draft/searching_functions.py @@ -1,3 +1,6 @@ +__all__ = ["argmax", "argmin", "nonzero", "where"] + + from ._types import Optional, Tuple, array @@ -102,6 +105,3 @@ def where(condition: array, x1: array, x2: array, /) -> array: out: array an array with elements from ``x1`` where ``condition`` is ``True``, and elements from ``x2`` elsewhere. The returned array must have a data type determined by :ref:`type-promotion` rules with the arrays ``x1`` and ``x2``. """ - - -__all__ = ["argmax", "argmin", "nonzero", "where"] diff --git a/src/array_api_stubs/_draft/set_functions.py b/src/array_api_stubs/_draft/set_functions.py index 661d3df90..394fa2b17 100644 --- a/src/array_api_stubs/_draft/set_functions.py +++ b/src/array_api_stubs/_draft/set_functions.py @@ -1,3 +1,6 @@ +__all__ = ["unique_all", "unique_counts", "unique_inverse", "unique_values"] + + from ._types import Tuple, array @@ -166,6 +169,3 @@ def unique_values(x: array, /) -> array: .. versionchanged:: 2022.12 Added complex data type support. """ - - -__all__ = ["unique_all", "unique_counts", "unique_inverse", "unique_values"] diff --git a/src/array_api_stubs/_draft/sorting_functions.py b/src/array_api_stubs/_draft/sorting_functions.py index 3eb52c8ce..2dc4ac410 100644 --- a/src/array_api_stubs/_draft/sorting_functions.py +++ b/src/array_api_stubs/_draft/sorting_functions.py @@ -1,3 +1,6 @@ +__all__ = ["argsort", "sort"] + + from ._types import array @@ -53,6 +56,3 @@ def sort( out : array a sorted array. The returned array must have the same data type and shape as ``x``. """ - - -__all__ = ["argsort", "sort"] diff --git a/src/array_api_stubs/_draft/statistical_functions.py b/src/array_api_stubs/_draft/statistical_functions.py index 93faaf31e..7648f1c3f 100644 --- a/src/array_api_stubs/_draft/statistical_functions.py +++ b/src/array_api_stubs/_draft/statistical_functions.py @@ -1,3 +1,6 @@ +__all__ = ["max", "mean", "min", "prod", "std", "sum", "var"] + + from ._types import Optional, Tuple, Union, array, dtype @@ -315,6 +318,3 @@ def var( - If ``N - correction`` is less than or equal to ``0``, the variance is ``NaN``. - If ``x_i`` is ``NaN``, the variance is ``NaN`` (i.e., ``NaN`` values propagate). """ - - -__all__ = ["max", "mean", "min", "prod", "std", "sum", "var"] diff --git a/src/array_api_stubs/_draft/utility_functions.py b/src/array_api_stubs/_draft/utility_functions.py index 64e5de297..81d8dca41 100644 --- a/src/array_api_stubs/_draft/utility_functions.py +++ b/src/array_api_stubs/_draft/utility_functions.py @@ -1,3 +1,6 @@ +__all__ = ["all", "any"] + + from ._types import Optional, Tuple, Union, array @@ -81,6 +84,3 @@ def any( .. versionchanged:: 2022.12 Added complex data type support. """ - - -__all__ = ["all", "any"]