Skip to content

Commit 253b5ab

Browse files
committed
Best practices for type hint stub files (flake8-pyi)
1 parent 10d2225 commit 253b5ab

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,

0 commit comments

Comments
 (0)