Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3d23775

Browse files
committed
Best practices for type hint stub files (flake8-pyi)
1 parent 6225f4c commit 3d23775

Some content is hidden

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

46 files changed

+184
-169
lines changed

lib/matplotlib/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ import os
3232
from pathlib import Path
3333

3434
from . import cbook, rcsetup
35-
from collections.abc import Generator, MutableMapping
35+
from collections.abc import Callable, Generator, MutableMapping
3636
import contextlib
3737
from packaging.version import Version
3838

3939
from matplotlib._api import MatplotlibDeprecationWarning
4040
from matplotlib.cbook import sanitize_sequence
4141
from matplotlib.rcsetup import cycler, validate_backend
42-
from typing import Any, Callable, NamedTuple
42+
from typing import Any, NamedTuple
4343

4444
__bibtex__: str
4545

lib/matplotlib/_path.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Sequence
1+
from collections.abc import Sequence
22
import numpy as np
33
from .transforms import BboxBase
44

lib/matplotlib/animation.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import abc
2-
from collections.abc import Generator
2+
from collections.abc import Callable, Iterable, Generator
33
import contextlib
44
from pathlib import Path
55
from matplotlib import cbook
@@ -13,7 +13,7 @@ from matplotlib.artist import Artist
1313
from matplotlib.backend_bases import TimerBase
1414
from matplotlib.figure import Figure
1515

16-
from typing import Any, Callable, Iterable, Generator, Type
16+
from typing import Any
1717

1818
subprocess_creation_flags: int
1919

@@ -23,11 +23,11 @@ class MovieWriterRegistry:
2323
def __init__(self) -> None: ...
2424
def register(
2525
self, name: str
26-
) -> Callable[[Type[AbstractMovieWriter]], Type[AbstractMovieWriter]]: ...
26+
) -> Callable[[type[AbstractMovieWriter]], type[AbstractMovieWriter]]: ...
2727
def is_available(self, name: str) -> bool: ...
2828
def __iter__(self) -> Generator[str, None, None]: ...
2929
def list(self) -> list[str]: ...
30-
def __getitem__(self, name: str) -> Type[AbstractMovieWriter]: ...
30+
def __getitem__(self, name: str) -> type[AbstractMovieWriter]: ...
3131

3232
writers: MovieWriterRegistry
3333

lib/matplotlib/artist.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ from .transforms import (
1919

2020
import numpy as np
2121

22-
from typing import Any, NamedTuple, Callable, TextIO, Type, TypeVar, overload
22+
from collections.abc import Callable
23+
from typing import Any, NamedTuple, TextIO, overload
2324
from numpy.typing import ArrayLike
2425

2526
def allow_rasterization(draw): ...
@@ -135,7 +136,7 @@ class Artist:
135136
def set(self, **kwargs: Any): ...
136137
def findobj(
137138
self,
138-
match: None | Callable[[Artist], bool] | Type[Artist] = ...,
139+
match: None | Callable[[Artist], bool] | type[Artist] = ...,
139140
include_self: bool = ...,
140141
) -> list[Artist]: ...
141142
def get_cursor_data(self, event: MouseEvent) -> Any: ...
@@ -144,8 +145,8 @@ class Artist:
144145
def set_mouseover(self, mouseover: bool) -> None: ...
145146

146147
class ArtistInspector:
147-
oorig: Artist | Type[Artist]
148-
o: Type[Artist]
148+
oorig: Artist | type[Artist]
149+
o: type[Artist]
149150
aliasd: dict[str, set[str]]
150151
def __init__(self, o) -> None: ...
151152
def get_aliases(self) -> dict[str, set[str]]: ...

lib/matplotlib/axes/_axes.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import matplotlib.streamplot as mstream
3232

3333
import datetime
3434
import PIL
35-
from typing import Any, Callable, Literal, Sequence, Type, overload
35+
from collections.abc import Callable, Sequence
36+
from typing import Any, Literal, overload
3637
import numpy as np
3738
from numpy.typing import ArrayLike
3839

@@ -49,7 +50,7 @@ class Axes(_AxesBase):
4950
**kwargs
5051
) -> Text: ...
5152
def get_legend_handles_labels(
52-
self, legend_handler_map: dict[Type, HandlerBase] | None = ...
53+
self, legend_handler_map: dict[type, HandlerBase] | None = ...
5354
) -> tuple[list[Artist], list[Any]]: ...
5455
legend_: Legend
5556

lib/matplotlib/axes/_base.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import matplotlib.artist as martist
22

33
import datetime
4-
from collections.abc import MutableSequence
4+
from collections.abc import Callable, Iterable, Iterator, Sequence, MutableSequence
55
from matplotlib import cbook, offsetbox
66
from matplotlib.artist import Artist
77
from matplotlib.axis import XAxis, YAxis, Tick
@@ -28,7 +28,7 @@ from cycler import Cycler
2828

2929
import numpy as np
3030
from numpy.typing import ArrayLike
31-
from typing import Any, Callable, Literal, Iterable, Iterator, Sequence, Type, overload
31+
from typing import Any, Literal, overload
3232

3333
class _axis_method_wrapper:
3434
attr_name: str
@@ -129,8 +129,8 @@ class _AxesBase(martist.Artist):
129129
self,
130130
axes: _AxesBase,
131131
prop_name: str,
132-
valid_types: list[Type] | None = ...,
133-
invalid_types: tuple[Type] | None = ...,
132+
valid_types: list[type] | None = ...,
133+
invalid_types: tuple[type] | None = ...,
134134
) -> None: ...
135135
def __len__(self) -> int: ...
136136
def __iter__(self) -> Iterator[Artist]: ...

lib/matplotlib/axes/_secondary_axes.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ from matplotlib.axis import Axis, Tick
44
from matplotlib.colors import Color
55
from matplotlib.transforms import Transform
66

7-
from typing import Literal, Callable, Iterable
7+
from collections.abc import Callable, Iterable
8+
from typing import Literal
89
from numpy.typing import ArrayLike
910

1011
class SecondaryAxis(_AxesBase):

lib/matplotlib/axis.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ from matplotlib.ticker import Locator, Formatter
99
from matplotlib.transforms import Transform, Bbox
1010

1111
import datetime
12-
from typing import Any, Literal, Type, Iterable, Callable
12+
from collections.abc import Callable, Iterable
13+
from typing import Any, Literal
1314
import numpy as np
1415
from numpy.typing import ArrayLike
1516

@@ -93,7 +94,7 @@ class Ticker:
9394

9495
class _LazyTickList:
9596
def __init__(self, major: bool) -> None: ...
96-
def __get__(self, instance: Axis, cls: Type): ...
97+
def __get__(self, instance: Axis, cls: type): ...
9798

9899
class Axis(martist.Artist):
99100
OFFSETTEXTPAD: int

lib/matplotlib/backend_bases.pyi

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ from matplotlib.texmanager import TexManager
2828
from matplotlib.text import Text
2929
from matplotlib.transforms import Affine2D, Transform, TransformedPath, Bbox
3030

31-
from typing import Any, Callable, Literal, NamedTuple, Sequence, Type, TypeVar
31+
from collections.abc import Callable, Sequence
32+
from typing import Any, Literal, NamedTuple, TypeVar
3233
from numpy.typing import ArrayLike
3334

3435
def register_backend(
35-
format: str, backend: str | Type[FigureCanvasBase], description: str | None = ...
36+
format: str, backend: str | type[FigureCanvasBase], description: str | None = ...
3637
) -> None: ...
37-
def get_registered_canvas_class(format: str) -> Type[FigureCanvasBase]: ...
38+
def get_registered_canvas_class(format: str) -> type[FigureCanvasBase]: ...
3839

3940
class RendererBase:
4041
def __init__(self) -> None: ...
@@ -302,7 +303,7 @@ class FigureCanvasBase:
302303
required_interactive_framework: str | None
303304

304305
@_api.classproperty
305-
def manager_class(cls) -> Type[FigureManagerBase]: ...
306+
def manager_class(cls) -> type[FigureManagerBase]: ...
306307
events: list[str]
307308
fixed_dpi: None | float
308309
filetypes: dict[str, str]
@@ -358,8 +359,8 @@ class FigureCanvasBase:
358359
@classmethod
359360
def get_default_filetype(cls) -> str: ...
360361
def get_default_filename(self) -> str: ...
361-
T = TypeVar("T", bound=FigureCanvasBase)
362-
def switch_backends(self, FigureCanvasClass: Type[T]) -> T: ...
362+
_T = TypeVar("_T", bound=FigureCanvasBase)
363+
def switch_backends(self, FigureCanvasClass: type[_T]) -> _T: ...
363364
def mpl_connect(self, s: str, func: Callable[[Event], Any]) -> int: ...
364365
def mpl_disconnect(self, cid: int) -> None: ...
365366
def new_timer(
@@ -394,7 +395,7 @@ class FigureManagerBase:
394395
def __init__(self, canvas: FigureCanvasBase, num: int | str) -> None: ...
395396
@classmethod
396397
def create_with_canvas(
397-
cls, canvas_class: Type[FigureCanvasBase], figure: Figure, num: int | str
398+
cls, canvas_class: type[FigureCanvasBase], figure: Figure, num: int | str
398399
): ...
399400
@classmethod
400401
def start_main_loop(cls) -> None: ...
@@ -475,8 +476,8 @@ class ToolContainerBase:
475476

476477
class _Backend:
477478
backend_version: str
478-
FigureCanvas: Type[FigureCanvasBase]
479-
FigureManager: Type[FigureManagerBase]
479+
FigureCanvas: type[FigureCanvasBase]
480+
FigureManager: type[FigureManagerBase]
480481
mainloop: None | Callable[[], Any]
481482
@classmethod
482483
def new_figure_manager(cls, num: int | str, *args, **kwargs): ...
@@ -487,7 +488,7 @@ class _Backend:
487488
@classmethod
488489
def show(cls, *, block: bool | None = ...) -> None: ...
489490
@staticmethod
490-
def export(cls) -> Type[_Backend]: ...
491+
def export(cls) -> type[_Backend]: ...
491492

492493
class ShowBase(_Backend):
493494
def __call__(self, block: bool | None = ...): ...

lib/matplotlib/backend_managers.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from matplotlib import backend_tools, cbook, widgets
1+
from matplotlib import backend_tools, widgets
22
from matplotlib.backend_bases import FigureCanvasBase
33
from matplotlib.figure import Figure
44

5-
from typing import Any, Callable, Iterable, TypeVar, Type
5+
from collections.abc import Callable, Iterable
6+
from typing import Any, TypeVar
67

78
class ToolEvent:
89
name: str
@@ -47,8 +48,8 @@ class ToolManager:
4748
def get_tool_keymap(self, name: str) -> list[str]: ...
4849
def update_keymap(self, name: str, key: str | Iterable[str]) -> None: ...
4950
def remove_tool(self, name: str) -> None: ...
50-
T = TypeVar("T", bound=backend_tools.ToolBase)
51-
def add_tool(self, name: str, tool: Type[T], *args, **kwargs) -> T: ...
51+
_T = TypeVar("_T", bound=backend_tools.ToolBase)
52+
def add_tool(self, name: str, tool: type[_T], *args, **kwargs) -> _T: ...
5253
def trigger_tool(
5354
self,
5455
name: str,

lib/matplotlib/backend_tools.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from matplotlib.figure import Figure
77
from matplotlib.scale import ScaleBase
88
from matplotlib._pylab_helpers import Gcf
99

10-
from typing import Any, Type
10+
from typing import Any
1111

1212
class Cursors(enum.IntEnum):
1313
POINTER: int
@@ -119,6 +119,6 @@ default_tools: dict[str, ToolBase]
119119
default_toolbar_tools: list[list[str | list[str]]]
120120

121121
def add_tools_to_manager(
122-
toolmanager: ToolManager, tools: dict[str, Type[ToolBase]] = ...
122+
toolmanager: ToolManager, tools: dict[str, type[ToolBase]] = ...
123123
) -> None: ...
124124
def add_tools_to_container(container: ToolContainerBase, tools: list[Any]) -> None: ...

lib/matplotlib/bezier.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Callable, Literal
1+
from collections.abc import Callable
2+
from typing import Literal
23

34
import numpy as np
45
from numpy.typing import ArrayLike

lib/matplotlib/cbook.pyi

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import collections.abc
2-
from collections.abc import Collection, Generator
2+
from collections.abc import Callable, Collection, Generator, Iterable, Iterator
33
import contextlib
44
import io
55
import os
@@ -12,17 +12,13 @@ from numpy.typing import ArrayLike
1212

1313
from typing import (
1414
Any,
15-
Callable,
16-
Iterable,
17-
Iterator,
1815
Generic,
1916
Literal,
2017
TypeVar,
21-
Type,
2218
overload,
2319
)
2420

25-
T = TypeVar("T")
21+
_T = TypeVar("_T")
2622

2723
class CallbackRegistry:
2824
exception_handler: Callable[[Exception], Any]
@@ -39,9 +35,9 @@ class CallbackRegistry:
3935
@contextlib.contextmanager
4036
def blocked(self, *, signal: Any | None = ...): ...
4137

42-
class silent_list(list[T]):
38+
class silent_list(list[_T]):
4339
type: str | None
44-
def __init__(self, type, seq: Iterable[T] | None = ...) -> None: ...
40+
def __init__(self, type, seq: Iterable[_T] | None = ...) -> None: ...
4541

4642
def strip_math(s: str) -> str: ...
4743
def is_writable_file_like(obj: Any) -> bool: ...
@@ -77,41 +73,41 @@ def flatten(
7773
seq: Iterable[Any], scalarp: Callable[[Any], bool] = ...
7874
) -> Generator[Any, None, None]: ...
7975

80-
class Stack(Generic[T]):
81-
def __init__(self, default: T | None = ...) -> None: ...
82-
def __call__(self) -> T: ...
76+
class Stack(Generic[_T]):
77+
def __init__(self, default: _T | None = ...) -> None: ...
78+
def __call__(self) -> _T: ...
8379
def __len__(self) -> int: ...
84-
def __getitem__(self, ind: int) -> T: ...
85-
def forward(self) -> T: ...
86-
def back(self) -> T: ...
87-
def push(self, o: T) -> T: ...
88-
def home(self) -> T: ...
80+
def __getitem__(self, ind: int) -> _T: ...
81+
def forward(self) -> _T: ...
82+
def back(self) -> _T: ...
83+
def push(self, o: _T) -> _T: ...
84+
def home(self) -> _T: ...
8985
def empty(self) -> bool: ...
9086
def clear(self) -> None: ...
91-
def bubble(self, o: T) -> T: ...
92-
def remove(self, o: T) -> None: ...
87+
def bubble(self, o: _T) -> _T: ...
88+
def remove(self, o: _T) -> None: ...
9389

9490
def safe_masked_invalid(x: ArrayLike, copy: bool = ...) -> np.ndarray: ...
9591
def print_cycles(
9692
objects: Iterable[Any], outstream: io.FileIO = ..., show_progress: bool = ...
9793
) -> None: ...
9894

99-
class Grouper(Generic[T]):
100-
def __init__(self, init: Iterable[T] = ...) -> None: ...
101-
def __contains__(self, item: T) -> bool: ...
95+
class Grouper(Generic[_T]):
96+
def __init__(self, init: Iterable[_T] = ...) -> None: ...
97+
def __contains__(self, item: _T) -> bool: ...
10298
def clean(self) -> None: ...
103-
def join(self, a: T, *args: T) -> None: ...
104-
def joined(self, a: T, b: T) -> bool: ...
105-
def remove(self, a: T) -> None: ...
106-
def __iter__(self) -> Iterator[list[T]]: ...
107-
def get_siblings(self, a: T) -> list[T]: ...
108-
109-
class GrouperView(Generic[T]):
110-
def __init__(self, grouper: Grouper[T]) -> None: ...
111-
def __contains__(self, item: T) -> bool: ...
112-
def __iter__(self) -> Iterator[list[T]]: ...
113-
def joined(self, a: T, b: T) -> bool: ...
114-
def get_siblings(self, a: T) -> list[T]: ...
99+
def join(self, a: _T, *args: _T) -> None: ...
100+
def joined(self, a: _T, b: _T) -> bool: ...
101+
def remove(self, a: _T) -> None: ...
102+
def __iter__(self) -> Iterator[list[_T]]: ...
103+
def get_siblings(self, a: _T) -> list[_T]: ...
104+
105+
class GrouperView(Generic[_T]):
106+
def __init__(self, grouper: Grouper[_T]) -> None: ...
107+
def __contains__(self, item: _T) -> bool: ...
108+
def __iter__(self) -> Iterator[list[_T]]: ...
109+
def joined(self, a: _T, b: _T) -> bool: ...
110+
def get_siblings(self, a: _T) -> list[_T]: ...
115111

116112
def simple_linear_interpolation(a: ArrayLike, steps: int) -> np.ndarray: ...
117113
def delete_masked_points(*args): ...
@@ -138,11 +134,11 @@ def pts_to_midstep(x: np.ndarray, *args: np.ndarray) -> np.ndarray: ...
138134
STEP_LOOKUP_MAP: dict[str, Callable]
139135

140136
def index_of(y: float | ArrayLike) -> tuple[np.ndarray, np.ndarray]: ...
141-
def safe_first_element(obj: Collection[T]) -> T: ...
137+
def safe_first_element(obj: Collection[_T]) -> _T: ...
142138
def sanitize_sequence(data): ...
143139
def normalize_kwargs(
144140
kw: dict[str, Any],
145-
alias_mapping: dict[str, list[str]] | Type[Artist] | Artist | None = ...,
141+
alias_mapping: dict[str, list[str]] | type[Artist] | Artist | None = ...,
146142
) -> dict[str, Any]: ...
147143

148144
class _OrderedSet(collections.abc.MutableSet):

0 commit comments

Comments
 (0)