Skip to content

Commit 8f294ae

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/python-type-stubs into Fix-most-misc
2 parents f640878 + e049074 commit 8f294ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+528
-203
lines changed

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ disable_error_code = [
156156
# `assert-type` issues is tests mostly comme from checking overloads
157157
# Since this project is specific to Pylance, just ignore them
158158
"assert-type",
159+
# Incompatible overrides are out of our stubs' control
160+
# as they are inherited from the implementation.
161+
"override",
159162
# TODO
160-
"valid-type", # 967 errors in 115 files
161-
"override", # 790 errors in 220 files
162163
"assignment", # 773 errors in 172 files
163-
"attr-defined", # 202 errors in 75 files
164164
]
165165

166166
[[tool.mypy.overrides]]

stubs/matplotlib/_typing.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import decimal
21
import io
32
import typing_extensions
3+
from decimal import Decimal as Decimal
44

5-
import numpy.typing
65
import pandas as pd
6+
from numpy.typing import ArrayLike as ArrayLike
77

8-
Decimal = decimal.Decimal
98
PythonScalar: typing_extensions.TypeAlias = str | int | float | bool
109

11-
ArrayLike = numpy.typing.ArrayLike
1210
FileLike = io.IOBase
1311
PathLike = str
1412

stubs/matplotlib/backend_bases.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class FigureCanvasBase:
310310
def mpl_connect(self, s: str, func: Callable) -> int: ...
311311
def mpl_disconnect(self, cid: int): ...
312312
_timer_cls = TimerBase
313-
def new_timer(self, interval: int = ..., callbacks: list[tuple[Callable, tuple, dict]] = ...) -> _timer_cls: ...
313+
def new_timer(self, interval: int = ..., callbacks: list[tuple[Callable, tuple, dict]] = ...) -> TimerBase: ...
314314
def flush_events(self) -> None: ...
315315
def start_event_loop(self, timeout: int = ...) -> None: ...
316316
def stop_event_loop(self) -> None: ...

stubs/matplotlib/backend_tools.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class ToolBase:
3232
def figure(self) -> Figure: ...
3333
@figure.setter
3434
def figure(self, figure: Figure) -> None: ...
35-
36-
set_figure = figure.fset
35+
def set_figure(self, figure: Figure) -> None: ...
3736
def trigger(self, sender: object, event: Event, data: object = ...) -> None: ...
3837
def destroy(self) -> None: ...
3938

stubs/matplotlib/backends/qt_compat.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, TypeAlias
1+
from typing import Any
2+
from typing_extensions import TypeAlias
23

34
QT_API_PYQT6: str = ...
45
QT_API_PYSIDE6: str = ...

stubs/matplotlib/transforms.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,23 @@ class Bbox(BboxBase):
137137
updatex: bool = True,
138138
updatey: bool = True,
139139
): ...
140-
@BboxBase.x0.setter
140+
@BboxBase.x0.setter # type: ignore[attr-defined] # python/mypy#5936
141141
def x0(self, val: float): ...
142-
@BboxBase.y0.setter
142+
@BboxBase.y0.setter # type: ignore[attr-defined] # python/mypy#5936
143143
def y0(self, val: float): ...
144-
@BboxBase.x1.setter
144+
@BboxBase.x1.setter # type: ignore[attr-defined] # python/mypy#5936
145145
def x1(self, val: float): ...
146-
@BboxBase.y1.setter
146+
@BboxBase.y1.setter # type: ignore[attr-defined] # python/mypy#5936
147147
def y1(self, val: float): ...
148-
@BboxBase.p0.setter
148+
@BboxBase.p0.setter # type: ignore[attr-defined] # python/mypy#5936
149149
def p0(self, val: float): ...
150-
@BboxBase.p1.setter
150+
@BboxBase.p1.setter # type: ignore[attr-defined] # python/mypy#5936
151151
def p1(self, val: float): ...
152-
@BboxBase.intervalx.setter
152+
@BboxBase.intervalx.setter # type: ignore[attr-defined] # python/mypy#5936
153153
def intervalx(self, interval): ...
154-
@BboxBase.intervaly.setter
154+
@BboxBase.intervaly.setter # type: ignore[attr-defined] # python/mypy#5936
155155
def intervaly(self, interval): ...
156-
@BboxBase.bounds.setter
156+
@BboxBase.bounds.setter # type: ignore[attr-defined] # python/mypy#5936
157157
def bounds(self, bounds): ...
158158
@property
159159
def minpos(self) -> float: ...

stubs/sklearn/_typing.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22
# to simplify the stubs generated by docs2stub. They are not
33
# intended to be used directly by other users.
44

5-
import decimal
65
import io
76
import typing_extensions
7+
from decimal import Decimal as Decimal
88

99
import numpy as np
10-
import numpy.typing
1110
import pandas as pd
11+
from numpy.typing import ArrayLike as ArrayLike
1212
from scipy.sparse import spmatrix
1313

1414
from .base import BaseEstimator, ClassifierMixin, RegressorMixin
1515

16-
Decimal = decimal.Decimal
1716
PythonScalar: typing_extensions.TypeAlias = str | int | float | bool
1817

19-
ArrayLike = numpy.typing.ArrayLike
2018
MatrixLike: typing_extensions.TypeAlias = np.ndarray | pd.DataFrame | spmatrix
2119
FileLike = io.IOBase
2220
PathLike = str

stubs/sklearn/linear_model/_base.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ from numpy import ndarray
66
from numpy.random.mtrand import RandomState
77

88
from .._typing import ArrayLike, Int, MatrixLike
9-
from ..base import BaseEstimator, ClassifierMixin, MultiOutputMixin, RegressorMixin
9+
from ..base import BaseEstimator as BaseEstimator, ClassifierMixin, MultiOutputMixin, RegressorMixin
1010
from ..utils._seq_dataset import ArrayDataset64, CSRDataset64
1111
from ._stochastic_gradient import SGDClassifier
1212

13-
# TODO: bayesian_ridge_regression and bayesian_regression_ard
14-
# should be squashed into its respective objects.
15-
1613
SPARSE_INTERCEPT_DECAY: float = ...
1714

1815
def make_dataset(
@@ -27,8 +24,6 @@ class LinearModel(BaseEstimator, metaclass=ABCMeta):
2724
def fit(self, X, y): ...
2825
def predict(self, X: MatrixLike) -> ndarray: ...
2926

30-
# XXX Should this derive from LinearModel? It should be a mixin, not an ABC.
31-
# Maybe the n_features checking can be moved to LinearModel.
3227
class LinearClassifierMixin(ClassifierMixin):
3328
def decision_function(self, X: MatrixLike | ArrayLike) -> ndarray: ...
3429
def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ...
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from typing import Final, NamedTuple
2+
3+
SIMPLE_METHODS = ...
4+
COMPOSITE_METHODS = ...
5+
METHODS = ...
6+
7+
def _routing_enabled(): ...
8+
def _raise_for_params(params, owner, method) -> None: ...
9+
def _raise_for_unsupported_routing(obj, method, **kwargs) -> None: ...
10+
11+
class _RoutingNotSupportedMixin:
12+
def get_metadata_routing(self) -> None: ...
13+
14+
UNUSED: Final = "$UNUSED$"
15+
WARN: Final = "$WARN$"
16+
UNCHANGED: Final = "$UNCHANGED$"
17+
VALID_REQUEST_VALUES = ...
18+
19+
def request_is_alias(item): ...
20+
def request_is_valid(item): ...
21+
22+
class MethodMetadataRequest:
23+
owner = ...
24+
method = ...
25+
def __init__(self, owner, method, requests=None) -> None: ...
26+
@property
27+
def requests(self): ...
28+
def add_request(self, *, param, alias): ...
29+
30+
class MetadataRequest:
31+
owner = ...
32+
def __init__(self, owner) -> None: ...
33+
def consumes(self, method, params): ...
34+
def __getattr__(self, name): ...
35+
36+
class RouterMappingPair(NamedTuple):
37+
mapping = ...
38+
router = ...
39+
40+
class MethodPair(NamedTuple):
41+
caller = ...
42+
callee = ...
43+
44+
class MethodMapping:
45+
def __init__(self) -> None: ...
46+
def __iter__(self): ...
47+
def add(self, *, caller, callee): ...
48+
49+
class MetadataRouter:
50+
owner = ...
51+
def __init__(self, owner) -> None: ...
52+
def add_self_request(self, obj): ...
53+
def add(self, *, method_mapping, **objs): ...
54+
def consumes(self, method, params): ...
55+
def route_params(self, *, caller, params): ...
56+
def validate_metadata(self, *, method, params) -> None: ...
57+
def __iter__(self): ...
58+
59+
def get_routing_for_object(obj=None): ...
60+
61+
REQUESTER_DOC: Final[str]
62+
REQUESTER_DOC_PARAM: Final[str]
63+
REQUESTER_DOC_RETURN: Final[str]
64+
65+
class RequestMethod:
66+
name = ...
67+
keys = ...
68+
validate_keys = ...
69+
def __init__(self, name, keys, validate_keys: bool = True) -> None: ...
70+
def __get__(self, instance, owner): ...
71+
72+
class _MetadataRequester:
73+
def set_fit_request(self, **kwargs): ...
74+
def set_partial_fit_request(self, **kwargs): ...
75+
def set_predict_request(self, **kwargs): ...
76+
def set_predict_proba_request(self, **kwargs): ...
77+
def set_predict_log_proba_request(self, **kwargs): ...
78+
def set_decision_function_request(self, **kwargs): ...
79+
def set_score_request(self, **kwargs): ...
80+
def set_split_request(self, **kwargs): ...
81+
def set_transform_request(self, **kwargs): ...
82+
def set_inverse_transform_request(self, **kwargs): ...
83+
def __init_subclass__(cls, **kwargs): ...
84+
def get_metadata_routing(self): ...
85+
86+
def process_routing(_obj, _method, /, **kwargs): ...
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from ._metadata_requests import (
2+
UNCHANGED as UNCHANGED,
3+
UNUSED as UNUSED,
4+
WARN as WARN,
5+
MetadataRequest as MetadataRequest,
6+
MetadataRouter as MetadataRouter,
7+
MethodMapping as MethodMapping,
8+
_MetadataRequester as _MetadataRequester,
9+
_raise_for_params as _raise_for_params,
10+
_raise_for_unsupported_routing as _raise_for_unsupported_routing,
11+
_routing_enabled as _routing_enabled,
12+
_RoutingNotSupportedMixin as _RoutingNotSupportedMixin,
13+
get_routing_for_object as get_routing_for_object,
14+
process_routing as process_routing,
15+
)

0 commit comments

Comments
 (0)