Skip to content
6 changes: 0 additions & 6 deletions ci/mypy-stubtest-allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ matplotlib\.backends\..*
matplotlib\.tests(\..*)?
matplotlib\.pylab(\..*)?
matplotlib\._.*
matplotlib\.rcsetup\._listify_validator
matplotlib\.rcsetup\._validate_linestyle
matplotlib\.ft2font\.Glyph
matplotlib\.ft2font\.LayoutItem
Expand Down Expand Up @@ -39,11 +38,6 @@ matplotlib\.figure\.Figure\.set_tight_layout
matplotlib\.tri\..*TriInterpolator\.__call__
matplotlib\.tri\..*TriInterpolator\.gradient

# TypeVar used only in type hints
matplotlib\.backend_bases\.FigureCanvasBase\._T
matplotlib\.backend_managers\.ToolManager\._T
matplotlib\.spines\.Spine\._T

# Parameter inconsistency due to 3.10 deprecation
matplotlib\.figure\.FigureBase\.get_figure

Expand Down
19 changes: 8 additions & 11 deletions lib/matplotlib/_api/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Callable, Generator, Iterable, Mapping, Sequence
from typing import Any, TypeVar, overload
from typing import Self
from typing import Any, Self, overload

from numpy.typing import NDArray

Expand All @@ -16,15 +15,13 @@ from .deprecation import ( # noqa: F401, re-exported API
MatplotlibDeprecationWarning as MatplotlibDeprecationWarning,
)

_T = TypeVar("_T")

class _Unset: ...
UNSET = _Unset()

class classproperty(Any):
class classproperty[T](Any):
def __init__(
self,
fget: Callable[[_T], Any],
fget: Callable[[T], Any],
fset: None = ...,
fdel: None = ...,
doc: str | None = None,
Expand All @@ -34,22 +31,22 @@ class classproperty(Any):
@overload
def __get__(self, instance: object, owner: type[object]) -> Any: ...
@property
def fget(self) -> Callable[[_T], Any]: ...
def fget(self) -> Callable[[T], Any]: ...

def check_isinstance(
types: type | tuple[type | None, ...], /, **kwargs: Any
) -> None: ...
def list_suggestion_error_msg(name: str, potential: Any, values: Sequence[Any]) -> str: ...
def check_in_list(values: Sequence[Any], /, **kwargs: Any) -> None: ...
def check_shape(shape: tuple[int | None, ...], /, **kwargs: NDArray) -> None: ...
def getitem_checked(mapping: Mapping[Any, _T], /, _error_cls: type[Exception] = ..., **kwargs: Any) -> _T: ...
def getitem_checked[T](mapping: Mapping[Any, T], /, _error_cls: type[Exception] = ..., **kwargs: Any) -> T: ...
def caching_module_getattr(cls: type) -> Callable[[str], Any]: ...
@overload
def define_aliases(
def define_aliases[T](
alias_d: dict[str, list[str]], cls: None = ...
) -> Callable[[type[_T]], type[_T]]: ...
) -> Callable[[type[T]], type[T]]: ...
@overload
def define_aliases(alias_d: dict[str, list[str]], cls: type[_T]) -> type[_T]: ...
def define_aliases[T](alias_d: dict[str, list[str]], cls: type[T]) -> type[T]: ...
def select_matching_signature(
funcs: list[Callable], *args: Any, **kwargs: Any
) -> Any: ...
Expand Down
46 changes: 21 additions & 25 deletions lib/matplotlib/_api/deprecation.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from collections.abc import Callable
import contextlib
from typing import Any, Literal, ParamSpec, TypedDict, TypeVar, Unpack, overload

_P = ParamSpec("_P")
_R = TypeVar("_R")
_T = TypeVar("_T")
from typing import Any, Literal, TypedDict, Unpack, overload

class MatplotlibDeprecationWarning(DeprecationWarning): ...

Expand All @@ -20,9 +16,9 @@ class NamedDeprecationKwargs(DeprecationKwargs, total=False):
name: str

def warn_deprecated(since: str, **kwargs: Unpack[NamedDeprecationKwargs]) -> None: ...
def deprecated(
def deprecated[T](
since: str, **kwargs: Unpack[NamedDeprecationKwargs]
) -> Callable[[_T], _T]: ...
) -> Callable[[T], T]: ...

class deprecate_privatize_attribute(Any):
def __init__(self, since: str, **kwargs: Unpack[NamedDeprecationKwargs]): ...
Expand All @@ -31,42 +27,42 @@ class deprecate_privatize_attribute(Any):
DECORATORS: dict[Callable, Callable] = ...

@overload
def rename_parameter(
def rename_parameter[**P, R](
since: str, old: str, new: str, func: None = ...
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
@overload
def rename_parameter(
since: str, old: str, new: str, func: Callable[_P, _R]
) -> Callable[_P, _R]: ...
def rename_parameter[**P, R](
since: str, old: str, new: str, func: Callable[P, R]
) -> Callable[P, R]: ...

class _deprecated_parameter_class: ...

_deprecated_parameter: _deprecated_parameter_class

@overload
def delete_parameter(
def delete_parameter[**P, R](
since: str, name: str, func: None = ..., **kwargs: Unpack[DeprecationKwargs]
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
@overload
def delete_parameter(
since: str, name: str, func: Callable[_P, _R], **kwargs: Unpack[DeprecationKwargs]
) -> Callable[_P, _R]: ...
def delete_parameter[**P, R](
since: str, name: str, func: Callable[P, R], **kwargs: Unpack[DeprecationKwargs]
) -> Callable[P, R]: ...
@overload
def make_keyword_only(
def make_keyword_only[**P, R](
since: str, name: str, func: None = ...
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
@overload
def make_keyword_only(
since: str, name: str, func: Callable[_P, _R]
) -> Callable[_P, _R]: ...
def deprecate_method_override(
method: Callable[_P, _R],
def make_keyword_only[**P, R](
since: str, name: str, func: Callable[P, R]
) -> Callable[P, R]: ...
def deprecate_method_override[**P, R](
method: Callable[P, R],
obj: object | type,
*,
allow_empty: bool = ...,
since: str,
**kwargs: Unpack[NamedDeprecationKwargs]
) -> Callable[_P, _R]: ...
) -> Callable[P, R]: ...
def suppress_matplotlib_deprecation_warning() -> (
contextlib.AbstractContextManager[None]
): ...
13 changes: 5 additions & 8 deletions lib/matplotlib/_docstring.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
from collections.abc import Callable
from typing import Any, TypeVar, overload
from typing import Any, overload


_T = TypeVar('_T')


def kwarg_doc(text: str) -> Callable[[_T], _T]: ...
def kwarg_doc[T](text: str) -> Callable[[T], T]: ...


class Substitution:
@overload
def __init__(self, *args: str): ...
@overload
def __init__(self, **kwargs: str): ...
def __call__(self, func: _T) -> _T: ...
def __call__[T](self, func: T) -> T: ...


class _ArtistKwdocLoader(dict[str, str]):
Expand All @@ -23,10 +20,10 @@ class _ArtistKwdocLoader(dict[str, str]):
class _ArtistPropertiesSubstitution:
def __init__(self) -> None: ...
def register(self, **kwargs) -> None: ...
def __call__(self, obj: _T) -> _T: ...
def __call__[T](self, obj: T) -> T: ...


def copy(source: Any) -> Callable[[_T], _T]: ...
def copy[T](source: Any) -> Callable[[T], T]: ...


dedent_interpd: _ArtistPropertiesSubstitution
Expand Down
7 changes: 3 additions & 4 deletions lib/matplotlib/_mathtext_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from __future__ import annotations
from typing import TypeAlias, overload
from typing import overload

from .ft2font import CharacterCodeType

Expand Down Expand Up @@ -1177,9 +1177,8 @@
# Each element is a 4-tuple of the form:
# src_start, src_end, dst_font, dst_start

_EntryTypeIn: TypeAlias = tuple[str, str, str, str | CharacterCodeType]
_EntryTypeOut: TypeAlias = tuple[CharacterCodeType, CharacterCodeType, str,
CharacterCodeType]
type _EntryTypeIn = tuple[str, str, str, str | CharacterCodeType]
type _EntryTypeOut = tuple[CharacterCodeType, CharacterCodeType, str, CharacterCodeType]

_stix_virtual_fonts: dict[str, dict[str, list[_EntryTypeIn]] | list[_EntryTypeIn]] = {
'bb': {
Expand Down
14 changes: 6 additions & 8 deletions lib/matplotlib/artist.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ from .transforms import (
import numpy as np

from collections.abc import Callable, Iterable
from typing import Any, Literal, NamedTuple, TextIO, overload, TypeVar
from typing import Any, Literal, NamedTuple, TextIO, overload
from numpy.typing import ArrayLike

_T_Artist = TypeVar("_T_Artist", bound=Artist)

def allow_rasterization(draw): ...

class _XYPair(NamedTuple):
x: ArrayLike
y: ArrayLike
x: list[float]
y: list[float]

class Artist:
zorder: float
Expand Down Expand Up @@ -143,11 +141,11 @@ class Artist:
) -> list[Artist]: ...

@overload
def findobj(
def findobj[T: Artist](
self,
match: type[_T_Artist],
match: type[T],
include_self: bool = ...,
) -> list[_T_Artist]: ...
) -> list[T]: ...

def get_cursor_data(self, event: MouseEvent) -> Any: ...
def format_cursor_data(self, data: Any) -> str: ...
Expand Down
6 changes: 1 addition & 5 deletions lib/matplotlib/axes/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from typing import TypeVar

from ._axes import Axes as Axes


_T = TypeVar("_T")

# Backcompat.
Subplot = Axes

Expand All @@ -13,4 +9,4 @@ class _SubplotBaseMeta(type):

class SubplotBase(metaclass=_SubplotBaseMeta): ...

def subplot_class_factory(cls: type[_T]) -> type[_T]: ...
def subplot_class_factory[T](cls: type[T]) -> type[T]: ...
18 changes: 8 additions & 10 deletions lib/matplotlib/axes/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ from cycler import Cycler

import numpy as np
from numpy.typing import ArrayLike
from typing import Any, Literal, TypeVar, overload
from typing import Any, Literal, overload
from matplotlib.typing import ColorType

_T = TypeVar("_T", bound=Artist)

class _axis_method_wrapper:
attr_name: str
method_name: str
Expand Down Expand Up @@ -67,7 +65,7 @@ class _AxesBase(martist.Artist):

def __init__(
self,
fig: Figure,
fig: Figure | SubFigure,
*args: tuple[float, float, float, float] | Bbox | int,
facecolor: ColorType | None = ...,
frameon: bool = ...,
Expand Down Expand Up @@ -136,7 +134,7 @@ class _AxesBase(martist.Artist):
def clear(self) -> None: ...
def cla(self) -> None: ...

class ArtistList(Sequence[_T]):
class ArtistList[T: Artist](Sequence[T]):
def __init__(
self,
axes: _AxesBase,
Expand All @@ -145,21 +143,21 @@ class _AxesBase(martist.Artist):
invalid_types: type | Iterable[type] | None = ...,
) -> None: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[_T]: ...
def __iter__(self) -> Iterator[T]: ...
@overload
def __getitem__(self, key: int) -> _T: ...
def __getitem__(self, key: int) -> T: ...
@overload
def __getitem__(self, key: slice) -> list[_T]: ...
def __getitem__(self, key: slice) -> list[T]: ...

@overload
def __add__(self, other: _AxesBase.ArtistList[_T]) -> list[_T]: ...
def __add__(self, other: _AxesBase.ArtistList[T]) -> list[T]: ...
@overload
def __add__(self, other: list[Any]) -> list[Any]: ...
@overload
def __add__(self, other: tuple[Any]) -> tuple[Any]: ...

@overload
def __radd__(self, other: _AxesBase.ArtistList[_T]) -> list[_T]: ...
def __radd__(self, other: _AxesBase.ArtistList[T]) -> list[T]: ...
@overload
def __radd__(self, other: list[Any]) -> list[Any]: ...
@overload
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/backend_bases.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ from matplotlib.text import Text, TextToPath
from matplotlib.transforms import Bbox, BboxBase, Transform, TransformedPath

from collections.abc import Callable, Iterable, Sequence
from typing import Any, IO, Literal, NamedTuple, TypeVar, overload
from typing import Any, IO, Literal, NamedTuple, overload
from numpy.typing import ArrayLike
from .typing import (
CapStyleType,
Expand Down Expand Up @@ -362,7 +362,6 @@ class FigureCanvasBase:
@classmethod
def get_default_filetype(cls) -> str: ...
def get_default_filename(self) -> str: ...
_T = TypeVar("_T", bound=FigureCanvasBase)

@overload
def mpl_connect(
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/backend_managers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from matplotlib.backend_bases import FigureCanvasBase
from matplotlib.figure import Figure

from collections.abc import Callable, Iterable
from typing import Any, TypeVar
from typing import Any

class ToolEvent:
name: str
Expand Down Expand Up @@ -48,8 +48,7 @@ class ToolManager:
def get_tool_keymap(self, name: str) -> list[str]: ...
def update_keymap(self, name: str, key: str | Iterable[str]) -> None: ...
def remove_tool(self, name: str) -> None: ...
_T = TypeVar("_T", bound=backend_tools.ToolBase)
def add_tool(self, name: str, tool: type[_T], *args, **kwargs) -> _T: ...
def add_tool[T: backend_tools.ToolBase](self, name: str, tool: type[T], *args, **kwargs) -> T: ...
def trigger_tool(
self,
name: str | backend_tools.ToolBase,
Expand Down
Loading
Loading