From 6f106378657e6b9a50f846fdb4d6550068d5abd0 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 19 Nov 2018 19:43:11 -0500 Subject: [PATCH] Use black to autoformat numpy-stubs --- .travis.yml | 1 + numpy-stubs/__init__.pyi | 209 ++++++++++----------------------- numpy-stubs/core/_internal.pyi | 3 - test-requirements.txt | 1 + 4 files changed, 67 insertions(+), 147 deletions(-) diff --git a/.travis.yml b/.travis.yml index 23cd4e0..ce393b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ install: script: - flake8 +- black --check numpy-stubs - py.test cache: diff --git a/numpy-stubs/__init__.pyi b/numpy-stubs/__init__.pyi index 883c216..454f685 100644 --- a/numpy-stubs/__init__.pyi +++ b/numpy-stubs/__init__.pyi @@ -27,6 +27,7 @@ from typing import ( if sys.version_info[0] < 3: class SupportsBytes: ... + else: from typing import SupportsBytes @@ -53,19 +54,25 @@ _DtypeLike = Union[ # (fixed_dtype, shape) Tuple[_DtypeLikeNested, _ShapeLike], # [(field_name, field_dtype, field_shape), ...] - List[Union[ - Tuple[Union[str, Tuple[str, str]], _DtypeLikeNested], - Tuple[Union[str, Tuple[str, str]], _DtypeLikeNested, _ShapeLike]]], + List[ + Union[ + Tuple[Union[str, Tuple[str, str]], _DtypeLikeNested], + Tuple[Union[str, Tuple[str, str]], _DtypeLikeNested, _ShapeLike], + ] + ], # {'names': ..., 'formats': ..., 'offsets': ..., 'titles': ..., # 'itemsize': ...} # TODO: use TypedDict when/if it's officially supported - Dict[str, Union[ - Sequence[str], # names - Sequence[_DtypeLikeNested], # formats - Sequence[int], # offsets - Sequence[Union[bytes, Text, None]], # titles - int, # itemsize - ]], + Dict[ + str, + Union[ + Sequence[str], # names + Sequence[_DtypeLikeNested], # formats + Sequence[int], # offsets + Sequence[Union[bytes, Text, None]], # titles + int, # itemsize + ], + ], # {'field1': ..., 'field2': ..., ...} Dict[str, Tuple[_DtypeLikeNested, int]], # (base_dtype, new_dtype) @@ -76,182 +83,127 @@ _NdArraySubClass = TypeVar("_NdArraySubClass", bound=ndarray) class dtype: names: Optional[Tuple[str, ...]] - - def __init__(self, - obj: _DtypeLike, - align: bool = ..., - copy: bool = ...) -> None: ... - + def __init__( + self, obj: _DtypeLike, align: bool = ..., copy: bool = ... + ) -> None: ... @property def alignment(self) -> int: ... - @property def base(self) -> dtype: ... - @property def byteorder(self) -> str: ... - @property def char(self) -> str: ... - @property - def descr(self) -> List[Union[ - Tuple[str, str], - Tuple[str, str, _Shape]]]: ... - + def descr(self) -> List[Union[Tuple[str, str], Tuple[str, str, _Shape]]]: ... @property - def fields(self) -> Optional[Mapping[ - str, - Union[Tuple[dtype, int], - Tuple[dtype, int, Any]]]]: ... - + def fields( + self + ) -> Optional[Mapping[str, Union[Tuple[dtype, int], Tuple[dtype, int, Any]]]]: ... @property def flags(self) -> int: ... - @property def hasobject(self) -> bool: ... - @property def isbuiltin(self) -> int: ... - @property def isnative(self) -> bool: ... - @property def isalignedstruct(self) -> bool: ... - @property def itemsize(self) -> int: ... - @property def kind(self) -> str: ... - @property def metadata(self) -> Optional[Mapping[str, Any]]: ... - @property def name(self) -> str: ... - @property def num(self) -> int: ... - @property def shape(self) -> _Shape: ... - @property def ndim(self) -> int: ... - @property def subdtype(self) -> Optional[Tuple[dtype, _Shape]]: ... - def newbyteorder(self, new_order: str = ...) -> dtype: ... - # Leave str and type for end to avoid having to use `builtins.str` # everywhere. See https://github.com/python/mypy/issues/3775 @property def str(self) -> builtins.str: ... - @property def type(self) -> Type[generic]: ... - _Dtype = dtype # to avoid name conflicts with ndarray.dtype - class _flagsobj: aligned: bool updateifcopy: bool writeable: bool writebackifcopy: bool - @property def behaved(self) -> bool: ... - @property def c_contiguous(self) -> bool: ... - @property def carray(self) -> bool: ... - @property def contiguous(self) -> bool: ... - @property def f_contiguous(self) -> bool: ... - @property def farray(self) -> bool: ... - @property def fnc(self) -> bool: ... - @property def forc(self) -> bool: ... - @property def fortran(self) -> bool: ... - @property def num(self) -> int: ... - @property def owndata(self) -> bool: ... - def __getitem__(self, key: str) -> bool: ... def __setitem__(self, key: str, value: bool) -> None: ... - class flatiter: @property def base(self) -> ndarray: ... - @property def coords(self) -> _Shape: ... - @property def index(self) -> int: ... - def copy(self) -> ndarray: ... def __iter__(self) -> flatiter: ... def __next__(self) -> Any: ... - _ArraySelf = TypeVar("_ArraySelf", bound=_ArrayOrScalarCommon) -class _ArrayOrScalarCommon(SupportsInt, SupportsFloat, SupportsComplex, - SupportsBytes, SupportsAbs[Any]): + +class _ArrayOrScalarCommon( + SupportsInt, SupportsFloat, SupportsComplex, SupportsBytes, SupportsAbs[Any] +): @property def T(self: _ArraySelf) -> _ArraySelf: ... - @property def base(self) -> Optional[ndarray]: ... - @property def dtype(self) -> _Dtype: ... - @property def data(self) -> memoryview: ... - @property def flags(self) -> _flagsobj: ... - @property def size(self) -> int: ... - @property def itemsize(self) -> int: ... - @property def nbytes(self) -> int: ... - @property def ndim(self) -> int: ... - @property def shape(self) -> _Shape: ... - @property def strides(self) -> _Shape: ... - def __int__(self) -> int: ... def __float__(self) -> float: ... def __complex__(self) -> complex: ... @@ -265,112 +217,86 @@ class _ArrayOrScalarCommon(SupportsInt, SupportsFloat, SupportsComplex, def __bytes__(self) -> bytes: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... - def __copy__(self: _ArraySelf, order: str = ...) -> _ArraySelf: ... def __deepcopy__(self: _ArraySelf, memo: dict) -> _ArraySelf: ... - def __lt__(self, other): ... def __le__(self, other): ... def __eq__(self, other): ... def __ne__(self, other): ... def __gt__(self, other): ... def __ge__(self, other): ... - def __add__(self, other): ... def __radd__(self, other): ... def __iadd__(self, other): ... - def __sub__(self, other): ... def __rsub__(self, other): ... def __isub__(self, other): ... - def __mul__(self, other): ... def __rmul__(self, other): ... def __imul__(self, other): ... - if sys.version_info[0] < 3: def __div__(self, other): ... def __rdiv__(self, other): ... def __idiv__(self, other): ... - def __truediv__(self, other): ... def __rtruediv__(self, other): ... def __itruediv__(self, other): ... - def __floordiv__(self, other): ... def __rfloordiv__(self, other): ... def __ifloordiv__(self, other): ... - def __mod__(self, other): ... def __rmod__(self, other): ... def __imod__(self, other): ... - def __divmod__(self, other): ... def __rdivmod__(self, other): ... - # NumPy's __pow__ doesn't handle a third argument def __pow__(self, other): ... def __rpow__(self, other): ... def __ipow__(self, other): ... - def __lshift__(self, other): ... def __rlshift__(self, other): ... def __ilshift__(self, other): ... - def __rshift__(self, other): ... def __rrshift__(self, other): ... def __irshift__(self, other): ... - def __and__(self, other): ... def __rand__(self, other): ... def __iand__(self, other): ... - def __xor__(self, other): ... def __rxor__(self, other): ... def __ixor__(self, other): ... - def __or__(self, other): ... def __ror__(self, other): ... def __ior__(self, other): ... - if sys.version_info[:2] >= (3, 5): def __matmul__(self, other): ... def __rmatmul__(self, other): ... - def __neg__(self: _ArraySelf) -> _ArraySelf: ... def __pos__(self: _ArraySelf) -> _ArraySelf: ... def __abs__(self: _ArraySelf) -> _ArraySelf: ... def __invert__(self: _ArraySelf) -> _ArraySelf: ... - # TODO(shoyer): remove when all methods are defined def __getattr__(self, name) -> Any: ... - class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container): real: ndarray imag: ndarray - @property def dtype(self) -> _Dtype: ... @dtype.setter def dtype(self, value: _DtypeLike): ... - @property def ctypes(self) -> _ctypes: ... - @property def shape(self) -> _Shape: ... @shape.setter def shape(self, value: _ShapeLike): ... - @property def flat(self) -> flatiter: ... - @property def strides(self) -> _Shape: ... @strides.setter def strides(self, value: _ShapeLike): ... - # Array conversion @overload def item(self, *args: int) -> Any: ... @@ -381,54 +307,55 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container): def itemset(self, __value: Any) -> None: ... @overload def itemset(self, __item: _ShapeLike, __value: Any) -> None: ... - def tostring(self, order: Optional[str]=...) -> bytes: ... - def tobytes(self, order: Optional[str]=...) -> bytes: ... - def tofile(self, - fid: Union[IO[bytes], str], - sep: str=..., - format: str=...) -> None: ... + def tostring(self, order: Optional[str] = ...) -> bytes: ... + def tobytes(self, order: Optional[str] = ...) -> bytes: ... + def tofile( + self, fid: Union[IO[bytes], str], sep: str = ..., format: str = ... + ) -> None: ... def dump(self, file: str) -> None: ... def dumps(self) -> bytes: ... - def astype(self, - dtype: _DtypeLike, - order: str=..., - casting: str=..., - subok: bool=..., - copy: bool=...) -> ndarray: ... - def byteswap(self, inplace: bool=...) -> ndarray: ... - def copy(self, order: str=...) -> ndarray: ... + def astype( + self, + dtype: _DtypeLike, + order: str = ..., + casting: str = ..., + subok: bool = ..., + copy: bool = ..., + ) -> ndarray: ... + def byteswap(self, inplace: bool = ...) -> ndarray: ... + def copy(self, order: str = ...) -> ndarray: ... @overload def view(self, dtype: Type[_NdArraySubClass]) -> _NdArraySubClass: ... @overload - def view(self, dtype: _DtypeLike=...) -> ndarray: ... + def view(self, dtype: _DtypeLike = ...) -> ndarray: ... @overload - def view(self, dtype: _DtypeLike, type: Type[_NdArraySubClass]) -> _NdArraySubClass: ... + def view( + self, dtype: _DtypeLike, type: Type[_NdArraySubClass] + ) -> _NdArraySubClass: ... @overload def view(self, *, type: Type[_NdArraySubClass]) -> _NdArraySubClass: ... - def getfield(self, - dtype: Union[_DtypeLike, str], - offset: int=...) -> ndarray: ... - def setflags(self, write: bool=..., align: bool=..., uic: bool=...) -> None: ... + def getfield(self, dtype: Union[_DtypeLike, str], offset: int = ...) -> ndarray: ... + def setflags( + self, write: bool = ..., align: bool = ..., uic: bool = ... + ) -> None: ... def fill(self, value: Any) -> None: ... - # Shape manipulation @overload - def reshape(self, shape: Sequence[int], *, order: str=...) -> ndarray: ... + def reshape(self, shape: Sequence[int], *, order: str = ...) -> ndarray: ... @overload - def reshape(self, *shape: int, order: str=...) -> ndarray: ... + def reshape(self, *shape: int, order: str = ...) -> ndarray: ... @overload - def resize(self, new_shape: Sequence[int], *, refcheck: bool=...) -> None: ... + def resize(self, new_shape: Sequence[int], *, refcheck: bool = ...) -> None: ... @overload - def resize(self, *new_shape: int, refcheck: bool=...) -> None: ... + def resize(self, *new_shape: int, refcheck: bool = ...) -> None: ... @overload def transpose(self, axes: Sequence[int]) -> ndarray: ... @overload def transpose(self, *axes: int) -> ndarray: ... def swapaxes(self, axis1: int, axis2: int) -> ndarray: ... - def flatten(self, order: str=...) -> ndarray: ... - def ravel(self, order: str=...) -> ndarray: ... - def squeeze(self, axis: Union[int, Tuple[int, ...]]=...) -> ndarray: ... - + def flatten(self, order: str = ...) -> ndarray: ... + def ravel(self, order: str = ...) -> ndarray: ... + def squeeze(self, axis: Union[int, Tuple[int, ...]] = ...) -> ndarray: ... # Many of these special methods are irrelevant currently, since protocols # aren't supported yet. That said, I'm adding them for completeness. # https://docs.python.org/3/reference/datamodel.html @@ -447,18 +374,15 @@ class generic(_ArrayOrScalarCommon): class _real_generic(generic): @property def real(self: _ArraySelf) -> _ArraySelf: ... - @property def imag(self: _ArraySelf) -> _ArraySelf: ... class number(generic): - def __init__( - self, value: Union[SupportsInt, SupportsFloat] = ... - ) -> None: ... + def __init__(self, value: Union[SupportsInt, SupportsFloat] = ...) -> None: ... + class bool_(_real_generic): ... class object_(generic): ... class datetime64(_real_generic): ... - class integer(number, _real_generic): ... class signedinteger(integer): ... class int8(signedinteger): ... @@ -466,13 +390,11 @@ class int16(signedinteger): ... class int32(signedinteger): ... class int64(signedinteger): ... class timedelta64(signedinteger): ... - class unsignedinteger(integer): ... class uint8(unsignedinteger): ... class uint16(unsignedinteger): ... class uint32(unsignedinteger): ... class uint64(unsignedinteger): ... - class inexact(number): ... class floating(inexact, _real_generic): ... class float16(floating): ... @@ -481,15 +403,15 @@ class float64(floating): ... class complexfloating(inexact): def __init__( - self, - value: Union[SupportsInt, SupportsFloat, SupportsComplex, - complex] = ..., + self, value: Union[SupportsInt, SupportsFloat, SupportsComplex, complex] = ... ) -> None: ... + class complex64(complexfloating): @property def real(self) -> float32: ... @property def imag(self) -> float32: ... + class complex128(complexfloating): @property def real(self) -> float64: ... @@ -510,14 +432,13 @@ class str_(character): ... # float128, complex256 # float96 - def array( object: object, dtype: _DtypeLike = ..., copy: bool = ..., subok: bool = ..., - ndmin: int = ...) -> ndarray: ... - + ndmin: int = ..., +) -> ndarray: ... # TODO(shoyer): remove when the full numpy namespace is defined def __getattr__(name: str) -> Any: ... diff --git a/numpy-stubs/core/_internal.pyi b/numpy-stubs/core/_internal.pyi index 9878bd4..1b3889e 100644 --- a/numpy-stubs/core/_internal.pyi +++ b/numpy-stubs/core/_internal.pyi @@ -5,13 +5,10 @@ from typing import Any class _ctypes: @property def data(self) -> int: ... - @property def shape(self) -> Any: ... - @property def strides(self) -> Any: ... - def data_as(self, obj: Any) -> Any: ... def shape_as(self, obj: Any) -> Any: ... def strides_as(self, obj: Any) -> Any: ... diff --git a/test-requirements.txt b/test-requirements.txt index 566b2b1..edabce2 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,4 @@ +black==18.9b0 flake8==3.6.0 flake8-pyi==18.3.1 pytest==4.0.0