Skip to content

Commit 1090643

Browse files
committed
🏷️ fix numpy.polynomial.*.basis_name stubtest errors
1 parent 55061e6 commit 1090643

File tree

8 files changed

+41
-42
lines changed

8 files changed

+41
-42
lines changed

src/numpy-stubs/polynomial/_polybase.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import abc
22
from collections.abc import Iterator, Mapping, Sequence
3-
from typing import Any, ClassVar, Final, Generic, Literal, SupportsIndex, TypeAlias, overload
4-
from typing_extensions import LiteralString, Self, TypeIs, TypeVar
3+
from typing import Any, ClassVar, Final, Literal, SupportsIndex, TypeAlias, overload
4+
from typing_extensions import Self, TypeIs, TypeVar
55

66
import numpy as np
77
import numpy.typing as npt
@@ -14,15 +14,14 @@ __all__: Final[Sequence[str]] = ("ABCPolyBase",)
1414

1515
###
1616

17-
_NameT_co = TypeVar("_NameT_co", bound=str | None, default=LiteralString | None, covariant=True)
1817
_PolyT = TypeVar("_PolyT", bound=ABCPolyBase)
1918

2019
_AnyOther: TypeAlias = ABCPolyBase | _ToNumeric_0d | CoComplex_1d
2120
_Hundred: TypeAlias = Literal[100]
2221

2322
###
2423

25-
class ABCPolyBase(abc.ABC, Generic[_NameT_co]):
24+
class ABCPolyBase(abc.ABC):
2625
__hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride]
2726
__array_ufunc__: ClassVar[None]
2827

@@ -31,14 +30,16 @@ class ABCPolyBase(abc.ABC, Generic[_NameT_co]):
3130
_subscript_mapping: ClassVar[Mapping[int, str]]
3231
_use_unicode: ClassVar[bool]
3332

34-
basis_name: _NameT_co
3533
coef: _InexactObject_1d
3634
domain: Array_1d[np.inexact]
3735
window: Array_1d[np.inexact]
3836

39-
_symbol: LiteralString
37+
_symbol: str
4038
@property
41-
def symbol(self, /) -> LiteralString: ...
39+
def symbol(self, /) -> str: ...
40+
@property
41+
@abc.abstractmethod
42+
def basis_name(self, /) -> str | None: ...
4243

4344
#
4445
def __init__(

src/numpy-stubs/polynomial/chebyshev.pyi

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ __all__ = [
7070
"poly2cheb",
7171
]
7272

73-
_SCT = TypeVar("_SCT", bound=np.number | np.object_)
74-
_RT = TypeVar("_RT", bound=np.number | np.bool | np.object_)
73+
_NumberT = TypeVar("_NumberT", bound=np.number | np.object_)
74+
_CoNumberT = TypeVar("_CoNumberT", bound=np.number | np.bool | np.object_)
7575

7676
###
7777

78-
def _cseries_to_zseries(c: Array[_SCT]) -> Array_1d[_SCT]: ...
79-
def _zseries_to_cseries(zs: Array[_SCT]) -> Array_1d[_SCT]: ...
80-
def _zseries_mul(z1: Array[_SCT], z2: Array[_SCT]) -> Array_1d[_SCT]: ...
81-
def _zseries_div(z1: Array[_SCT], z2: Array[_SCT]) -> Array_1d[_SCT]: ...
82-
def _zseries_der(zs: Array[_SCT]) -> Array_1d[_SCT]: ...
83-
def _zseries_int(zs: Array[_SCT]) -> Array_1d[_SCT]: ...
78+
def _cseries_to_zseries(c: Array[_NumberT]) -> Array_1d[_NumberT]: ...
79+
def _zseries_to_cseries(zs: Array[_NumberT]) -> Array_1d[_NumberT]: ...
80+
def _zseries_mul(z1: Array[_NumberT], z2: Array[_NumberT]) -> Array_1d[_NumberT]: ...
81+
def _zseries_div(z1: Array[_NumberT], z2: Array[_NumberT]) -> Array_1d[_NumberT]: ...
82+
def _zseries_der(zs: Array[_NumberT]) -> Array_1d[_NumberT]: ...
83+
def _zseries_int(zs: Array[_NumberT]) -> Array_1d[_NumberT]: ...
8484

8585
poly2cheb: Final[_FuncPoly2Ortho[L["poly2cheb"]]] = ...
8686
cheb2poly: Final[_FuncUnOp[L["cheb2poly"]]] = ...
@@ -121,15 +121,21 @@ chebpts2: Final[_FuncPts[L["chebpts2"]]] = ...
121121
@overload
122122
def chebinterpolate(func: np.ufunc, deg: _IntLike_co, args: tuple[()] = ...) -> Array[Any]: ...
123123
@overload
124-
def chebinterpolate(func: Callable[[Array[np.float64]], _RT], deg: _IntLike_co, args: tuple[()] = ...) -> Array[_RT]: ...
124+
def chebinterpolate(
125+
func: Callable[[Array[np.float64]], _CoNumberT],
126+
deg: _IntLike_co,
127+
args: tuple[()] = (),
128+
) -> Array[_CoNumberT]: ...
125129
@overload
126130
def chebinterpolate(
127-
func: Callable[Concatenate[Array[np.float64], ...], _RT],
131+
func: Callable[Concatenate[Array[np.float64], ...], _CoNumberT],
128132
deg: _IntLike_co,
129133
args: Iterable[Any],
130-
) -> Array[_RT]: ...
134+
) -> Array[_CoNumberT]: ...
135+
136+
class Chebyshev(ABCPolyBase):
137+
basis_name: L["T"] = "T" # pyright: ignore[reportIncompatibleMethodOverride]
131138

132-
class Chebyshev(ABCPolyBase[L["T"]]):
133139
@overload
134140
@classmethod
135141
def interpolate(
@@ -145,8 +151,7 @@ class Chebyshev(ABCPolyBase[L["T"]]):
145151
cls,
146152
func: Callable[Concatenate[Array[np.float64], ...], _ToNumeric_1d],
147153
deg: _IntLike_co,
148-
domain: CoComplex_1d | None = ...,
149-
*,
154+
domain: CoComplex_1d | None,
150155
args: Iterable[Any],
151156
) -> Self: ...
152157
@overload
@@ -155,6 +160,7 @@ class Chebyshev(ABCPolyBase[L["T"]]):
155160
cls,
156161
func: Callable[Concatenate[Array[np.float64], ...], _ToNumeric_1d],
157162
deg: _IntLike_co,
158-
domain: CoComplex_1d | None,
163+
domain: CoComplex_1d | None = ...,
164+
*,
159165
args: Iterable[Any],
160166
) -> Self: ...

src/numpy-stubs/polynomial/hermite.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ hermweight: Final[_FuncWeight[L["hermweight"]]] = ...
9999

100100
def _normed_hermite_n(x: Array[np.float64, _ShapeT], n: int | np.intp) -> Array[np.float64, _ShapeT]: ...
101101

102-
class Hermite(ABCPolyBase[L["H"]]): ...
102+
class Hermite(ABCPolyBase):
103+
basis_name: L["H"] = "H" # pyright: ignore[reportIncompatibleMethodOverride]

src/numpy-stubs/polynomial/hermite_e.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ __all__ = [
6363
"poly2herme",
6464
]
6565

66-
_ND = TypeVar("_ND", bound=tuple[int, ...])
66+
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
6767

6868
###
6969

@@ -99,6 +99,7 @@ hermeroots: Final[_FuncRoots[L["hermeroots"]]] = ...
9999
hermegauss: Final[_FuncGauss[L["hermegauss"]]] = ...
100100
hermeweight: Final[_FuncWeight[L["hermeweight"]]] = ...
101101

102-
def _normed_hermite_e_n(x: Array[np.float64, _ND], n: int | np.intp) -> Array[np.float64, _ND]: ...
102+
def _normed_hermite_e_n(x: Array[np.float64, _ShapeT], n: int | np.intp) -> Array[np.float64, _ShapeT]: ...
103103

104-
class HermiteE(ABCPolyBase[L["He"]]): ...
104+
class HermiteE(ABCPolyBase):
105+
basis_name: L["He"] = "He" # pyright: ignore[reportIncompatibleMethodOverride]

src/numpy-stubs/polynomial/laguerre.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ lagroots: Final[_FuncRoots[L["lagroots"]]] = ...
9494
laggauss: Final[_FuncGauss[L["laggauss"]]] = ...
9595
lagweight: Final[_FuncWeight[L["lagweight"]]] = ...
9696

97-
class Laguerre(ABCPolyBase[L["L"]]): ...
97+
class Laguerre(ABCPolyBase):
98+
basis_name: L["L"] = "L" # pyright: ignore[reportIncompatibleMethodOverride]

src/numpy-stubs/polynomial/legendre.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ legroots: Final[_FuncRoots[L["legroots"]]] = ...
9494
leggauss: Final[_FuncGauss[L["leggauss"]]] = ...
9595
legweight: Final[_FuncWeight[L["legweight"]]] = ...
9696

97-
class Legendre(ABCPolyBase[L["P"]]): ...
97+
class Legendre(ABCPolyBase):
98+
basis_name: L["P"] = "P" # pyright: ignore[reportIncompatibleMethodOverride]

src/numpy-stubs/polynomial/polynomial.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ polyfit: Final[_FuncFit[L["polyfit"]]] = ...
8484
polycompanion: Final[_FuncCompanion[L["polycompanion"]]] = ...
8585
polyroots: Final[_FuncRoots[L["polyroots"]]] = ...
8686

87-
class Polynomial(ABCPolyBase[None]): ...
87+
class Polynomial(ABCPolyBase):
88+
basis_name: None = None # pyright: ignore[reportIncompatibleMethodOverride]

tool/.mypyignore-todo

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,13 @@ numpy.ma.core.mask_rowcols
5656
numpy.ma.extras.MAxisConcatenator.concatenate
5757
numpy.ma.mrecords.fromtextfile
5858

59-
numpy.polynomial.Chebyshev.basis_name
60-
numpy.polynomial.Hermite.basis_name
61-
numpy.polynomial.HermiteE.basis_name
62-
numpy.polynomial.Laguerre.basis_name
63-
numpy.polynomial.Legendre.basis_name
64-
numpy.polynomial.Polynomial.basis_name
6559
numpy.polynomial._polybase.ABCPolyBase.__rdiv__
6660
numpy.polynomial._polybase.ABCPolyBase._repr_latex_term
6761
numpy.polynomial._polybase.ABCPolyBase._str_term_ascii
68-
numpy.polynomial._polybase.ABCPolyBase.basis_name
6962
numpy.polynomial._polybase.ABCPolyBase.cutdeg
7063
numpy.polynomial._polybase.ABCPolyBase.domain
7164
numpy.polynomial._polybase.ABCPolyBase.fromroots
7265
numpy.polynomial._polybase.ABCPolyBase.window
73-
numpy.polynomial.chebyshev.Chebyshev.basis_name
7466
numpy.polynomial.chebyshev.cheb2poly
7567
numpy.polynomial.chebyshev.chebadd
7668
numpy.polynomial.chebyshev.chebcompanion
@@ -99,7 +91,6 @@ numpy.polynomial.chebyshev.chebvander2d
9991
numpy.polynomial.chebyshev.chebvander3d
10092
numpy.polynomial.chebyshev.chebweight
10193
numpy.polynomial.chebyshev.poly2cheb
102-
numpy.polynomial.hermite.Hermite.basis_name
10394
numpy.polynomial.hermite.herm2poly
10495
numpy.polynomial.hermite.hermadd
10596
numpy.polynomial.hermite.hermcompanion
@@ -126,7 +117,6 @@ numpy.polynomial.hermite.hermvander2d
126117
numpy.polynomial.hermite.hermvander3d
127118
numpy.polynomial.hermite.hermweight
128119
numpy.polynomial.hermite.poly2herm
129-
numpy.polynomial.hermite_e.HermiteE.basis_name
130120
numpy.polynomial.hermite_e.herme2poly
131121
numpy.polynomial.hermite_e.hermeadd
132122
numpy.polynomial.hermite_e.hermecompanion
@@ -153,7 +143,6 @@ numpy.polynomial.hermite_e.hermevander2d
153143
numpy.polynomial.hermite_e.hermevander3d
154144
numpy.polynomial.hermite_e.hermeweight
155145
numpy.polynomial.hermite_e.poly2herme
156-
numpy.polynomial.laguerre.Laguerre.basis_name
157146
numpy.polynomial.laguerre.lag2poly
158147
numpy.polynomial.laguerre.lagadd
159148
numpy.polynomial.laguerre.lagcompanion
@@ -180,7 +169,6 @@ numpy.polynomial.laguerre.lagvander2d
180169
numpy.polynomial.laguerre.lagvander3d
181170
numpy.polynomial.laguerre.lagweight
182171
numpy.polynomial.laguerre.poly2lag
183-
numpy.polynomial.legendre.Legendre.basis_name
184172
numpy.polynomial.legendre.leg2poly
185173
numpy.polynomial.legendre.legadd
186174
numpy.polynomial.legendre.legcompanion
@@ -207,7 +195,6 @@ numpy.polynomial.legendre.legvander2d
207195
numpy.polynomial.legendre.legvander3d
208196
numpy.polynomial.legendre.legweight
209197
numpy.polynomial.legendre.poly2leg
210-
numpy.polynomial.polynomial.Polynomial.basis_name
211198
numpy.polynomial.polynomial.polyadd
212199
numpy.polynomial.polynomial.polycompanion
213200
numpy.polynomial.polynomial.polyder

0 commit comments

Comments
 (0)