diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index aa3602571c03..fbd724571d80 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -55,8 +55,7 @@ jobs: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -o pipefail - mypy --config pyproject.toml lib/matplotlib \ - --follow-imports silent | \ + mypy --config pyproject.toml | \ reviewdog -f=mypy -name=mypy \ -tee -reporter=github-check -filter-mode nofilter diff --git a/lib/matplotlib/__init__.pyi b/lib/matplotlib/__init__.pyi index 8ef23a3dc4c2..54b28a8318ef 100644 --- a/lib/matplotlib/__init__.pyi +++ b/lib/matplotlib/__init__.pyi @@ -68,6 +68,8 @@ def matplotlib_fname() -> str: ... class RcParams(dict[str, Any]): validate: dict[str, Callable] def __init__(self, *args, **kwargs) -> None: ... + def _set(self, key: str, val: Any) -> None: ... + def _get(self, key: str) -> Any: ... def __setitem__(self, key: str, val: Any) -> None: ... def __getitem__(self, key: str) -> Any: ... def __iter__(self) -> Generator[str, None, None]: ... diff --git a/lib/matplotlib/_type1font.py b/lib/matplotlib/_type1font.py index a3124a24579c..b3e08f52c035 100644 --- a/lib/matplotlib/_type1font.py +++ b/lib/matplotlib/_type1font.py @@ -21,12 +21,15 @@ v1.1, 1993. ISBN 0-201-57044-0. """ +from __future__ import annotations + import binascii import functools import logging import re import string import struct +import typing as T import numpy as np @@ -171,7 +174,7 @@ def value(self): return float(self.raw) -def _tokenize(data: bytes, skip_ws: bool): +def _tokenize(data: bytes, skip_ws: bool) -> T.Generator[_Token, int, None]: """ A generator that produces _Token instances from Type-1 font code. @@ -194,7 +197,7 @@ def _tokenize(data: bytes, skip_ws: bool): hex_re = re.compile(r'^<[0-9a-fA-F\0\t\r\f\n ]*>$') oct_re = re.compile(r'[0-7]{1,3}') pos = 0 - next_binary = None + next_binary: int | None = None while pos < len(text): if next_binary is not None: diff --git a/lib/matplotlib/patheffects.pyi b/lib/matplotlib/patheffects.pyi index 5d8dcfeab61a..2c1634ca9314 100644 --- a/lib/matplotlib/patheffects.pyi +++ b/lib/matplotlib/patheffects.pyi @@ -55,7 +55,7 @@ class Normal(AbstractPathEffect): ... class Stroke(AbstractPathEffect): def __init__(self, offset: tuple[float, float] = ..., **kwargs) -> None: ... # rgbFace becomes non-optional - def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore + def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override] class withStroke(Stroke): ... @@ -69,7 +69,7 @@ class SimplePatchShadow(AbstractPathEffect): **kwargs ) -> None: ... # rgbFace becomes non-optional - def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore + def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override] class withSimplePatchShadow(SimplePatchShadow): ... @@ -83,13 +83,13 @@ class SimpleLineShadow(AbstractPathEffect): **kwargs ) -> None: ... # rgbFace becomes non-optional - def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore + def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override] class PathPatchEffect(AbstractPathEffect): patch: Patch def __init__(self, offset: tuple[float, float] = ..., **kwargs) -> None: ... # rgbFace becomes non-optional - def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore + def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override] class TickedStroke(AbstractPathEffect): def __init__( @@ -101,6 +101,6 @@ class TickedStroke(AbstractPathEffect): **kwargs ) -> None: ... # rgbFace becomes non-optional - def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore + def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override] class withTickedStroke(TickedStroke): ... diff --git a/lib/matplotlib/projections/__init__.pyi b/lib/matplotlib/projections/__init__.pyi index 0f8b6c09803c..4e0d210f1c9e 100644 --- a/lib/matplotlib/projections/__init__.pyi +++ b/lib/matplotlib/projections/__init__.pyi @@ -1,5 +1,10 @@ -from .geo import AitoffAxes, HammerAxes, LambertAxes, MollweideAxes -from .polar import PolarAxes +from .geo import ( + AitoffAxes as AitoffAxes, + HammerAxes as HammerAxes, + LambertAxes as LambertAxes, + MollweideAxes as MollweideAxes, +) +from .polar import PolarAxes as PolarAxes from ..axes import Axes class ProjectionRegistry: diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 18cee79d55b9..53d2cf755893 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -69,7 +69,7 @@ from matplotlib.artist import Artist from matplotlib.axes import Axes from matplotlib.axes import Subplot # noqa: F401 -from matplotlib.projections import PolarAxes # type: ignore +from matplotlib.projections import PolarAxes from matplotlib import mlab # for detrend_none, window_hanning from matplotlib.scale import get_scale_names # noqa: F401 @@ -224,7 +224,7 @@ def install_repl_displayhook() -> None: ip.events.register("post_execute", _draw_all_if_interactive) _REPL_DISPLAYHOOK = _ReplDisplayHook.IPYTHON - from IPython.core.pylabtools import backend2gui # type: ignore + from IPython.core.pylabtools import backend2gui # trigger IPython's eventloop integration, if available ipython_gui_name = backend2gui.get(get_backend()) if ipython_gui_name: @@ -235,7 +235,7 @@ def uninstall_repl_displayhook() -> None: """Disconnect from the display hook of the current shell.""" global _REPL_DISPLAYHOOK if _REPL_DISPLAYHOOK is _ReplDisplayHook.IPYTHON: - from IPython import get_ipython # type: ignore + from IPython import get_ipython ip = get_ipython() ip.events.unregister("post_execute", _draw_all_if_interactive) _REPL_DISPLAYHOOK = _ReplDisplayHook.NONE @@ -274,7 +274,7 @@ def _get_backend_mod() -> type[matplotlib.backend_bases._Backend]: # Use rcParams._get("backend") to avoid going through the fallback # logic (which will (re)import pyplot and then call switch_backend if # we need to resolve the auto sentinel) - switch_backend(rcParams._get("backend")) # type: ignore[attr-defined] + switch_backend(rcParams._get("backend")) return cast(type[matplotlib.backend_bases._Backend], _backend_mod) @@ -744,7 +744,7 @@ def xkcd( "xkcd mode is not compatible with text.usetex = True") stack = ExitStack() - stack.callback(dict.update, rcParams, rcParams.copy()) # type: ignore + stack.callback(dict.update, rcParams, rcParams.copy()) # type: ignore[arg-type] from matplotlib import patheffects rcParams.update({ @@ -2501,10 +2501,10 @@ def polar(*args, **kwargs) -> list[Line2D]: # requested, ignore rcParams['backend'] and force selection of a backend that # is compatible with the current running interactive framework. if (rcParams["backend_fallback"] - and rcParams._get_backend_or_none() in ( # type: ignore + and rcParams._get_backend_or_none() in ( # type: ignore[attr-defined] set(rcsetup.interactive_bk) - {'WebAgg', 'nbAgg'}) - and cbook._get_running_interactive_framework()): # type: ignore - rcParams._set("backend", rcsetup._auto_backend_sentinel) # type: ignore + and cbook._get_running_interactive_framework()): + rcParams._set("backend", rcsetup._auto_backend_sentinel) # fmt: on diff --git a/pyproject.toml b/pyproject.toml index 7661d039d370..8d3ff39fc38e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -208,6 +208,11 @@ convention = "numpy" [tool.mypy] ignore_missing_imports = true +enable_error_code = [ + "ignore-without-code", + "redundant-expr", + "truthy-bool", +] enable_incomplete_feature = [ "Unpack", ] @@ -227,6 +232,11 @@ exclude = [ # stubtest will import and run, opening a figure if not excluded ".*/tinypages" ] +files = [ + "lib/matplotlib", +] +follow_imports = "silent" +warn_unreachable = true [tool.rstcheck] ignore_directives = [