Skip to content

Commit dad267d

Browse files
authored
Merge pull request #1651 from scipy/ruff/UP046
🚨 fix/ignore `UP046` ruff errors
2 parents f1570c7 + b1dcf90 commit dad267d

7 files changed

Lines changed: 23 additions & 28 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ ignore = [
285285
"FIX",
286286
"DOC",
287287
# TODO(@jorenham): https://github.com/scipy/scipy-stubs/pull/1615
288-
"UP046",
289288
"UP047",
290289
]
291290

scipy-stubs/integrate/_tanhsinh.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ _MaxLevelT_co = TypeVar("_MaxLevelT_co", covariant=True)
2727
@type_check_only
2828
class _TanhSinhResult(
2929
_RichResult[_ResultT_co | _SuccessT_co | _StatusT_co | _MaxLevelT_co],
30-
Generic[_ResultT_co, _SuccessT_co, _StatusT_co, _MaxLevelT_co],
30+
Generic[_ResultT_co, _SuccessT_co, _StatusT_co, _MaxLevelT_co], # noqa: UP046
3131
):
3232
integral: _ResultT_co
3333
error: _ResultT_co

scipy-stubs/io/_harwell_boeing/_fortran_format_parser.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import abc
22
import re
3-
from typing import Final, Generic, Literal, Self, TypeVar, type_check_only
3+
from typing import Final, Literal, Self, type_check_only
44

55
import optype.numpy as onp
66

77
__all__ = ["BadFortranFormat", "ExpFormat", "FortranFormatParser", "IntFormat"]
88

99
###
1010

11-
_NumberT = TypeVar("_NumberT", int, float)
12-
1311
type _TokenType = Literal["INT", "INT_ID", "EXP_ID", "DOT", "LPAR", "RPAR"]
1412

1513
###
@@ -19,7 +17,7 @@ TOKENS: Final[dict[_TokenType, str]]
1917
class BadFortranFormat(SyntaxError): ...
2018

2119
@type_check_only
22-
class _NumberFormat(Generic[_NumberT], metaclass=abc.ABCMeta):
20+
class _NumberFormat[NumberT: (int, float)](metaclass=abc.ABCMeta):
2321
width: Final[int]
2422
repeat: Final[int | None]
2523
min: Final[int | None]
@@ -28,7 +26,7 @@ class _NumberFormat(Generic[_NumberT], metaclass=abc.ABCMeta):
2826
@property
2927
def python_format(self, /) -> str: ...
3028
@classmethod
31-
def from_number(cls, n: _NumberT, min: int | None = None) -> Self: ...
29+
def from_number(cls, n: NumberT, min: int | None = None) -> Self: ...
3230

3331
class IntFormat(_NumberFormat[int]):
3432
def __init__(self, /, width: int, min: int | None = None, repeat: int | None = None) -> None: ...

scipy-stubs/linalg/_testutils.pyi

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
from _typeshed import Unused
22
from collections.abc import Callable, Iterable
3-
from typing import Any, Final, Generic, TypeVar
3+
from typing import Any, Final
44

55
import numpy as np
66
import optype.numpy as onp
77

8-
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
9-
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
8+
class _FakeMatrix[ScalarT: np.generic, ShapeT: tuple[int, ...]]: # undocumented
9+
_data: onp.ArrayND[ScalarT, ShapeT]
1010

11-
class _FakeMatrix(Generic[_ScalarT, _ShapeT]): # undocumented
12-
_data: onp.ArrayND[_ScalarT, _ShapeT]
13-
14-
def __init__(self, /, data: onp.ArrayND[_ScalarT, _ShapeT]) -> None: ...
11+
def __init__(self, /, data: onp.ArrayND[ScalarT, ShapeT]) -> None: ...
1512
__array_interface__: Final[Callable[[], dict[str, Any]]] = ...
1613

1714
@property
18-
def shape(self) -> _ShapeT: ...
15+
def shape(self) -> ShapeT: ...
1916

20-
class _FakeMatrix2(Generic[_ScalarT, _ShapeT]): # undocumented
21-
_data: onp.ArrayND[_ScalarT, _ShapeT]
22-
def __init__(self, /, data: onp.ArrayND[_ScalarT, _ShapeT]) -> None: ...
23-
def __array__(self, /, dtype: np.dtype[Any] | None = None, copy: bool | None = None) -> onp.ArrayND[_ScalarT, _ShapeT]: ...
17+
class _FakeMatrix2[ScalarT: np.generic, ShapeT: tuple[int, ...]]: # undocumented
18+
_data: onp.ArrayND[ScalarT, ShapeT]
19+
def __init__(self, /, data: onp.ArrayND[ScalarT, ShapeT]) -> None: ...
20+
def __array__(self, /, dtype: np.dtype[Any] | None = None, copy: bool | None = None) -> onp.ArrayND[ScalarT, ShapeT]: ...
2421
@property
25-
def shape(self) -> _ShapeT: ...
22+
def shape(self) -> ShapeT: ...
2623

27-
def _get_array(shape: _ShapeT, dtype: type[_ScalarT]) -> onp.ArrayND[_ScalarT, _ShapeT]: ... # undocumented
24+
def _get_array[ScalarT: np.generic, ShapeT: tuple[int, ...]](
25+
shape: ShapeT, dtype: type[ScalarT]
26+
) -> onp.ArrayND[ScalarT, ShapeT]: ... # undocumented
2827
def _id[T](x: T) -> T: ... # undocumented
2928

3029
#

scipy-stubs/optimize/_root.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ _ScalarT = TypeVar("_ScalarT", bound=npc.inexact)
1919
_ScalarT_co = TypeVar("_ScalarT_co", bound=npc.inexact, default=np.float64 | Any, covariant=True)
2020
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
2121
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], default=tuple[Any, ...], covariant=True)
22-
_JacOptionsT = TypeVar("_JacOptionsT", bound=Mapping[str, object])
2322

2423
@type_check_only
2524
class _RootOptionsHybr(TypedDict, total=False):
@@ -43,7 +42,7 @@ class _RootOptionsLM(TypedDict, total=False):
4342
diag: onp.ToFloat1D
4443

4544
@type_check_only
46-
class _RootOptionsNonlin(TypedDict, Generic[_JacOptionsT], total=False):
45+
class _RootOptionsNonlin[JacOptionsT: Mapping[str, object]](TypedDict, total=False):
4746
nit: int
4847
disp: bool
4948
maxiter: int
@@ -53,7 +52,7 @@ class _RootOptionsNonlin(TypedDict, Generic[_JacOptionsT], total=False):
5352
xatol: float
5453
tol_norm: Callable[[onp.Array1D[np.float64]], float]
5554
line_search: Literal["armijo", "wolfe"] | None
56-
jac_options: _JacOptionsT
55+
jac_options: JacOptionsT
5756

5857
@type_check_only
5958
class _JacOptionsBase(TypedDict, total=False):

scipy-stubs/stats/_distribution_infrastructure.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ _null: Final[_Null] = ...
162162

163163
def _isnull(x: object) -> TypeIs[_Null | None]: ...
164164

165-
class _Domain(abc.ABC, Generic[_XT_co]):
165+
class _Domain(abc.ABC, Generic[_XT_co]): # noqa: UP046
166166
@classmethod
167167
def __class_getitem__(cls, arg: object, /) -> types.GenericAlias: ...
168168

@@ -180,7 +180,7 @@ class _Domain(abc.ABC, Generic[_XT_co]):
180180
@abc.abstractmethod
181181
def get_numerical_endpoints(self, /, x: _ParamValues) -> tuple[onp.ArrayND[_OutFloat], onp.ArrayND[_OutFloat]]: ...
182182

183-
class _Interval(_Domain[_XT_co], Generic[_XT_co]): # pyrefly: ignore[implicit-abstract-class]
183+
class _Interval(_Domain[_XT_co], Generic[_XT_co]): # pyrefly: ignore[implicit-abstract-class] # noqa: UP046
184184
@override
185185
@abc.abstractmethod
186186
def __str__(self, /) -> str: ...

scipy-stubs/stats/_typing.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class BunchMixin(Generic[_TupleT_co]):
4848
# NOTE: `._asdict()` includes both `{fields}` and `{extra_fields}`
4949
def _asdict[T](self: BunchMixin[tuple[T, ...]], /) -> dict[str, T]: ...
5050

51-
@type_check_only
52-
class BaseBunch(tuple[*_Ts], BunchMixin[tuple[*_Ts]], Generic[*_Ts]):
51+
@type_check_only # ty currently (0.0.40) doens't support PEP 695 with variadic type parameters.
52+
class BaseBunch(tuple[*_Ts], BunchMixin[tuple[*_Ts]], Generic[*_Ts]): # noqa: UP046
5353
@abc.abstractmethod
5454
def __new__(_cls) -> Self: ...
5555
@abc.abstractmethod

0 commit comments

Comments
 (0)