Skip to content

Commit a050529

Browse files
committed
🐴 sparse.linalg: Work around a __new__ bug in mypy
1 parent 4a5adba commit a050529

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

.mypyignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# scipy-stubs internal helper types (typecheck-only)
22
scipy(\.\w+)?\._typing
33

4+
# https://github.com/python/mypy/issues/17251
5+
scipy\.sparse\.linalg(\._?interface|\.matfuncs)?\.LinearOperator\.__init__
6+
47
# scipy tests
58
scipy\.conftest
69
scipy\.((_|\w)+\.)+(__test__|test|tests(\..+)?)

scipy-stubs/sparse/linalg/_interface.pyi

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,21 @@ class LinearOperator(Generic[_SCT_co]):
170170
rmatmat: _FunMatMat | None = None,
171171
) -> _CustomLinearOperator[Any]: ...
172172

173-
#
174-
@overload
175-
def __init__(self, /, dtype: onp.ToDType[_SCT_co], shape: _ToShape) -> None: ...
176-
@overload
177-
def __init__(self: LinearOperator[np.int_], /, dtype: onp.AnyIntDType, shape: _ToShape) -> None: ...
178-
@overload
179-
def __init__(self: LinearOperator[np.float64], /, dtype: onp.AnyFloat64DType, shape: _ToShape) -> None: ...
180-
@overload
181-
def __init__(self: LinearOperator[np.complex128], /, dtype: onp.AnyComplex128DType, shape: _ToShape) -> None: ...
182-
@overload
183-
def __init__(self: LinearOperator[Any], /, dtype: type | str | None, shape: _ToShape) -> None: ...
173+
# NOTE: the `__init__` method cannot be annotated, because it will cause mypy to `__new__`:
174+
# https://github.com/python/mypy/issues/17251
175+
176+
# ruff: noqa: ERA001
177+
178+
# @overload
179+
# def __init__(self, /, dtype: onp.ToDType[_SCT_co], shape: _ToShape) -> None: ...
180+
# @overload
181+
# def __init__(self: LinearOperator[np.int_], /, dtype: onp.AnyIntDType, shape: _ToShape) -> None: ...
182+
# @overload
183+
# def __init__(self: LinearOperator[np.float64], /, dtype: onp.AnyFloat64DType, shape: _ToShape) -> None: ...
184+
# @overload
185+
# def __init__(self: LinearOperator[np.complex128], /, dtype: onp.AnyComplex128DType, shape: _ToShape) -> None: ...
186+
# @overload
187+
# def __init__(self: LinearOperator[Any], /, dtype: type | str | None, shape: _ToShape) -> None: ...
184188

185189
#
186190
@property

0 commit comments

Comments
 (0)