10000 CI,TYP: Bump mypy to 1.4.1 by charris · Pull Request #24541 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

CI,TYP: Bump mypy to 1.4.1 #24541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ dependencies:
- pytest-xdist
- hypothesis
# For type annotations
- mypy=0.981
- typing_extensions>=4.2.0
- typing_extensions>=4.2.0 # needed for python < 3.10
- mypy=1.4.1
# For building docs
- sphinx>=4.5.0
- sphinx-design
Expand Down
5 changes: 4 additions & 1 deletion numpy/core/numeric.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ from typing import (
SupportsIndex,
NoReturn,
)
from typing_extensions import TypeGuard
if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing_extensions import TypeGuard

from numpy import (
ComplexWarning as ComplexWarning,
Expand Down
21 changes: 13 additions & 8 deletions numpy/lib/shape_base.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import sys
from collections.abc import Callable, Sequence
from typing import TypeVar, Any, overload, SupportsIndex, Protocol

if sys.version_info >= (3, 10):
from typing import ParamSpec, Concatenate
else:
from typing_extensions import ParamSpec, Concatenate

from numpy import (
generic,
integer,
Expand Down Expand Up @@ -28,6 +34,7 8000 @@ from numpy._typing import (

from numpy.core.shape_base import vstack

_P = ParamSpec("_P")
_SCT = TypeVar("_SCT", bound=generic)

# The signatures of `__array_wrap__` and `__array_prepare__` are the same;
Expand Down Expand Up @@ -73,23 +80,21 @@ def put_along_axis(
axis: None | int,
) -> None: ...

# TODO: Use PEP 612 `ParamSpec` once mypy supports `Concatenate`
# xref python/mypy#8645
@overload
def apply_along_axis(
func1d: Callable[..., _ArrayLike[_SCT]],
func1d: Callable[Concatenate[NDArray[Any], _P], _ArrayLike[_SCT]],
axis: SupportsIndex,
arr: ArrayLike,
*args: Any,
**kwargs: Any,
*args: _P.args,
**kwargs: _P.kwargs,
) -> NDArray[_SCT]: ...
@overload
def apply_along_axis(
func1d: Callable[..., ArrayLike],
func1d: Callable[Concatenate[NDArray[Any], _P], ArrayLike],
axis: SupportsIndex,
arr: ArrayLike,
*args: Any,
**kwargs: Any,
*args: _P.args,
**kwargs: _P.kwargs,
) -> NDArray[Any]: ...

def apply_over_axes(
Expand Down
5 cha 6302 nges: 4 additions & 1 deletion numpy/testing/_private/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ from typing import (
Final,
SupportsIndex,
)
from typing_extensions import ParamSpec
if sys.version_info >= (3, 10):
from typing import ParamSpec
else:
from typing_extensions import ParamSpec

from numpy import generic, dtype, number, object_, bool_, _FloatValue
from numpy._typing import (
Expand Down
2 changes: 1 addition & 1 deletion numpy/typing/tests/data/fail/modules.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ np.bob # E: Module has no attribute
# Stdlib modules in the namespace by accident
np.warnings # E: Module has no attribute
np.sys # E: Module has no attribute
np.os # E: Module has no attribute
np.os # E: Module "numpy" does not explicitly export
np.math # E: Module has no attribute

# Public sub-modules that are not imported to their parent module by default;
Expand Down
3 changes: 0 additions & 3 deletions numpy/typing/tests/data/fail/npyio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ AR_i8: npt.NDArray[np.int64]
np.load(str_file) # E: incompatible type

np.save(bytes_path, AR_i8) # E: incompatible type
np.save(str_file, AR_i8) # E: incompatible type

np.savez(bytes_path, AR_i8) # E: incompatible type
np.savez(str_file, AR_i8) # E: incompatible type

np.savez_compressed(bytes_path, AR_i8) # E: incompatible type
np.savez_compressed(str_file, AR_i8) # E: incompatible type

np.loadtxt(bytes_path) # E: incompatible type

Expand Down
6 changes: 0 additions & 6 deletions numpy/typing/tests/data/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@
plugins = numpy.typing.mypy_plugin
show_absolute_path = True
implicit_reexport = False

[mypy-numpy]
ignore_errors = True

[mypy-numpy.*]
ignore_errors = True
5 changes: 4 additions & 1 deletion numpy/typing/tests/data/pass/lib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
FILE = StringIO()
AR = np.arange(10, dtype=np.float64)

def func(a: int) -> bool: ...

def func(a: int) -> bool:
return True


np.deprecate(func)
np.deprecate()
Expand Down
26 changes: 20 additions & 6 deletions numpy/typing/tests/data/pass/ufunc_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@

import numpy as np

def func1(a: str, b: int) -> None: ...
def func2(a: str, b: int, c: float = ...) -> None: ...
def func3(a: str, b: int) -> int: ...

def func1(a: str, b: int) -> None:
return None


def func2(a: str, b: int, c: float = 1.0) -> None:
return None


def func3(a: str, b: int) -> int:
return 0


class Write1:
def write(self, a: str) -> None: ...
def write(self, a: str) -> None:
return None


class Write2:
def write(self, a: str, b: int = ...) -> None: ...
def write(self, a: str, b: int = 1) -> None:
return None


class Write3:
def write(self, a: str) -> int: ...
def write(self, a: str) -> int:
return 0


_err_default = np.geterr()
Expand Down
104 changes: 44 additions & 60 deletions numpy/typing/tests/data/reveal/arithmetic.pyi
F438
Original file line number Diff line number Diff line change
Expand Up @@ -343,184 +343,168 @@ reveal_type(c8 / b_) # E: {complex64}

# Complex

reveal_type(c16 + f16) # E: {complex256}
reveal_type(c16 + f16) # E: complexfloating[Union[_64Bit, _128Bit], Union[_64Bit, _128Bit]]
reveal_type(c16 + c16) # E: {complex128}
reveal_type(c16 + f8) # E: {complex128}
reveal_type(c16 + i8) # E: {complex128}
reveal_type(c16 + c8) # E: {complex128}
reveal_type(c16 + f4) # E: {complex128}
reveal_type(c16 + i4) # E: {complex128}
reveal_type(c16 + c8) # E: complexfloating[Union[_64Bit, _32Bit], Union[_64Bit, _32Bit]]
reveal_type(c16 + f4) # E: complexfloating[Union[_64Bit, _32Bit], Union[_64Bit, _32Bit]]
reveal_type(c16 + i4) # E: complexfloating[Union[_64Bit, _32Bit], Union[_64Bit, _32Bit]]
reveal_type(c16 + b_) # E: {complex128}
reveal_type(c16 + b) # E: {complex128}
reveal_type(c16 + c) # E: {complex128}
reveal_type(c16 + f) # E: {complex128}
reveal_type(c16 + i) # E: {complex128}
reveal_type(c16 + AR_f) # E: Any

reveal_type(f16 + c16) # E: {complex256}
reveal_type(f16 + c16) # E: complexfloating[Union[_64Bit, _128Bit], Union[_64Bit, _128Bit]]
reveal_type(c16 + c16) # E: {complex128}
reveal_type(f8 + c16) # E: {complex128}
reveal_type(i8 + c16) # E: {complex128}
reveal_type(c8 + c16) # E: {complex128}
reveal_type(f4 + c16) # E: {complex128}
reveal_type(i4 + c16) # E: {complex128}
reveal_type(c8 + c16) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(f4 + c16) # E: complexfloating[Union[_64Bit, _32Bit], Union[_64Bit, _32Bit]]
reveal_type(i4 + c16) # E: complexfloating[Union[_64Bit, _32Bit], Union[_64Bit, _32Bit]]
reveal_type(b_ + c16) # E: {complex128}
reveal_type(b + c16) # E: {complex128}
reveal_type(c + c16) # E: {complex128}
reveal_type(f + c16) # E: {complex128}
reveal_type(i + c16) # E: {complex128}
reveal_type(AR_f + c16) # E: Any

reveal_type(c8 + f16) # E: {complex256}
reveal_type(c8 + c16) # E: {complex128}
reveal_type(c8 + f8) # E: {complex128}
reveal_type(c8 + i8) # E: {complex128}
reveal_type(c8 + f16) # E: complexfloating[Union[_32Bit, _128Bit], Union[_32Bit, _128Bit]]
reveal_type(c8 + c16) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(c8 + f8) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(c8 + i8) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(c8 + c8) # E: {complex64}
reveal_type(c8 + f4) # E: {complex64}
reveal_type(c8 + i4) # E: {complex64}
reveal_type(c8 + b_) # E: {complex64}
reveal_type(c8 + b) # E: {complex64}
reveal_type(c8 + c) # E: {complex128}
reveal_type(c8 + f) # E: {complex128}
reveal_type(c8 + i) # E: complexfloating[{_NBitInt}, {_NBitInt}]
reveal_type(c8 + c) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(c8 + f) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(c8 + AR_f) # E: Any

reveal_type(f16 + c8) # E: {complex256}
reveal_type(c16 + c8) # E: {complex128}
reveal_type(f8 + c8) # E: {complex128}
reveal_type(i8 + c8) # E: {complex128}
reveal_type(f16 + c8) # E: complexfloating[Union[_32Bit, _128Bit], Union[_32Bit, _128Bit]]
reveal_type(c16 + c8) # E: complexfloating[Union[_64Bit, _32Bit], Union[_64Bit, _32Bit]]
reveal_type(f8 + c8) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(i8 + c8) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(c8 + c8) # E: {complex64}
reveal_type(f4 + c8) # E: {complex64}
reveal_type(i4 + c8) # E: {complex64}
reveal_type(b_ + c8) # E: {complex64}
reveal_type(b + c8) # E: {complex64}
reveal_type(c + c8) # E: {complex128}
reveal_type(f + c8) # E: {complex128}
reveal_type(i + c8) # E: complexfloating[{_NBitInt}, {_NBitInt}]
reveal_type(c + c8) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(f + c8) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(AR_f + c8) # E: Any

# Float

reveal_type(f8 + f16) # E: {float128}
reveal_type(f8 + f16) # E: floating[Union[_64Bit, _128Bit]]
reveal_type(f8 + f8) # E: {float64}
reveal_type(f8 + i8) # E: {float64}
reveal_type(f8 + f4) # E: {float64}
reveal_type(f8 + i4) # E: {float64}
reveal_type(f8 + f4) # E: floating[Union[_64Bit, _32Bit]]
reveal_type(f8 + i4) # E: floating[Union[_64Bit, _32Bit]]
reveal_type(f8 + b_) # E: {float64}
reveal_type(f8 + b) # E: {float64}
reveal_type(f8 + c) # E: {complex128}
reveal_type(f8 + f) # E: {float64}
reveal_type(f8 + i) # E: {float64}
reveal_type(f8 + AR_f) # E: Any

reveal_type(f16 + f8) # E: {float128}
reveal_type(f16 + f8) # E: floating[Union[_128Bit, _64Bit]]
reveal_type(f8 + f8) # E: {float64}
reveal_type(i8 + f8) # E: {float64}
reveal_type(f4 + f8) # E: {float64}
reveal_type(i4 + f8) # E: {float64}
reveal_type(f4 + f8) # E: floating[Union[_32Bit, _64Bit]]
reveal_type(i4 + f8) # E: floating[Union[_64Bit, _32Bit]]
reveal_type(b_ + f8) # E: {float64}
reveal_type(b + f8) # E: {float64}
reveal_type(c + f8) # E: {complex128}
reveal_type(f + f8) # E: {float64}
reveal_type(i + f8) # E: {float64}
reveal_type(AR_f + f8) # E: Any

reveal_type(f4 + f16) # E: {float128}
reveal_type(f4 + f8) # E: {float64}
reveal_type(f4 + i8) # E: {float64}
reveal_type(f4 + f16) # E: floating[Union[_32Bit, _128Bit]]
reveal_type(f4 + f8) # E: floating[Union[_32Bit, _64Bit]]
reveal_type(f4 + i8) # E: floating[Union[_32Bit, _64Bit]]
reveal_type(f4 + f4) # E: {float32}
reveal_type(f4 + i4) # E: {float32}
reveal_type(f4 + b_) # E: {float32}
reveal_type(f4 + b) # E: {float32}
reveal_type(f4 + c) # E: {complex128}
reveal_type(f4 + f) # E: {float64}
reveal_type(f4 + i) # E: floating[{_NBitInt}]
reveal_type(f4 + c) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(f4 + f) # E: floating[Union[_32Bit, _64Bit]]
reveal_type(f4 + AR_f) # E: Any

reveal_type(f16 + f4) # E: {float128}
reveal_type(f8 + f4) # E: {float64}
reveal_type(i8 + f4) # E: {float64}
reveal_type(f16 + f4) # E: floating[Union[_128Bit, _32Bit]]
reveal_type(f8 + f4) # E: floating[Union[_64Bit, _32Bit]]
reveal_type(i8 + f4) # E: floating[Union[_32Bit, _64Bit]]
reveal_type(f4 + f4) # E: {float32}
reveal_type(i4 + f4) # E: {float32}
reveal_type(b_ + f4) # E: {float32}
reveal_type(b + f4) # E: {float32}
reveal_type(c + f4) # E: {complex128}
reveal_type(f + f4) # E: {float64}
reveal_type(i + f4) # E: floating[{_NBitInt}]
reveal_type(c + f4) # E: complexfloating[Union[_32Bit, _64Bit], Union[_32Bit, _64Bit]]
reveal_type(f + f4) # E: floating[Union[_32Bit, _64Bit]]
reveal_type(AR_f + f4) # E: Any

# Int

reveal_type(i8 + i8) # E: {int64}
reveal_type(i8 + u8) # E: Any
reveal_type(i8 + i4) # E: {int64}
reveal_type(i8 + i4) # E: signedinteger[Union[_64Bit, _32Bit]]
reveal_type(i8 + u4) # E: Any
reveal_type(i8 + b_) # E: {int64}
reveal_type(i8 + b) # E: {int64}
reveal_type(i8 + c) # E: {complex128}
reveal_type(i8 + f) # E: {float64}
reveal_type(i8 + i) # E: {int64}
reveal_type(i8 + AR_f) # E: Any

reveal_type(u8 + u8) # E: {uint64}
reveal_type(u8 + i4) # E: Any
reveal_type(u8 + u4) # E: {uint64}
reveal_type(u8 + u4) # E: signedinteger[Union[_64Bit, _32Bit]]
reveal_type(u8 + b_) # E: {uint64}
reveal_type(u8 + b) # E: {uint64}
reveal_type(u8 + c) # E: {complex128}
reveal_type(u8 + f) # E: {float64}
reveal_type(u8 + i) # E: Any
reveal_type(u8 + AR_f) # E: Any

reveal_type(i8 + i8) # E: {int64}
reveal_type(u8 + i8) # E: Any
reveal_type(i4 + i8) # E: {int64}
reveal_type(i4 + i8) # E: signedinteger[Union[_32Bit, _64Bit]]
reveal_type(u4 + i8) # E: Any
reveal_type(b_ + i8) # E: {int64}
reveal_type(b + i8) # E: {int64}
reveal_type(c + i8) # E: {complex128}
reveal_type(f + i8) # E: {float64}
reveal_type(i + i8) # E: {int64}
reveal_type(AR_f + i8) # E: Any

reveal_type(u8 + u8) # E: {uint64}
reveal_type(i4 + u8) # E: Any
reveal_type(u4 + u8) # E: {uint64}
reveal_type(u4 + u8) # E: unsignedinteger[Union[_32Bit, _64Bit]]
reveal_type(b_ + u8) # E: {uint64}
reveal_type(b + u8) # E: {uint64}
reveal_type(c + u8) # E: {complex128}
reveal_type(f + u8) # E: {float64}
reveal_type(i + u8) # E: Any
reveal_type(AR_f + u8) # E: Any

reveal_type(i4 + i8) # E: {int64}
reveal_type(i4 + i8) # E: signedinteger[Union[_32Bit, _64Bit]]
reveal_type(i4 + i4) # E: {int32}
reveal_type(i4 + i) # E: {int_}
reveal_type(i4 + b_) # E: {int32}
reveal_type(i4 + b) # E: {int32}
reveal_type(i4 + AR_f) # E: Any

reveal_type(u4 + i8) # E: Any
reveal_type(u4 + i4) # E: Any
reveal_type(u4 + u8) # E: {uint64}
reveal_type(u4 + u8) # E: unsignedinteger[Union[_32Bit, _64Bit]]
reveal_type(u4 + u4) # E: {uint32}
reveal_type(u4 + i) # E: Any
reveal_type(u4 + b_) # E: {uint32}
reveal_type(u4 + b) # E: {uint32}
reveal_type(u4 + AR_f) # E: Any

reveal_type(i8 + i4) # E: {int64}
reveal_type(i8 + i4) # E: signedinteger[Union[_64Bit, _32Bit]]
reveal_type(i4 + i4) # E: {int32}
reveal_type(i + i4) # E: {int_}
reveal_type(b_ + i4) # E: {int32}
reveal_type(b + i4) # E: {int32}
reveal_type(AR_f + i4) # E: Any

reveal_type(i8 + u4) # E: Any
reveal_type(i4 + u4) # E: Any
reveal_type(u8 + u4) # E: {uint64}
reveal_type(u8 + u4) # E: unsignedinteger[Union[_64Bit, _32Bit]]
reveal_type(u4 + u4) # E: {uint32}
reveal_type(b_ + u4) # E: {uint32}
reveal_type(b + u4) # E: {uint32}
reveal_type(i + u4) # E: Any
reveal_type(AR_f + u4) # E: Any
Loading
0