8000 Merge pull request #27796 from QuLogic/stricter-mypy · matplotlib/matplotlib@810a43b · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 810a43b

Browse files
authored
Merge pull request #27796 from QuLogic/stricter-mypy
Make mypy a bit stricter
2 parents af80c90 + bbd3723 commit 810a43b

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

.github/workflows/reviewdog.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ jobs:
5555
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5656
run: |
5757
set -o pipefail
58-
mypy --config pyproject.toml lib/matplotlib \
59-
--follow-imports silent | \
58+
mypy --config pyproject.toml | \
6059
reviewdog -f=mypy -name=mypy \
6160
-tee -reporter=github-check -filter-mode nofilter
6261

lib/matplotlib/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def matplotlib_fname() -> str: ...
6868
class RcParams(dict[str, Any]):
6969
validate: dict[str, Callable]
7070
def __init__(self, *args, **kwargs) -> None: ...
71+
def _set(self, key: str, val: Any) -> None: ...
72+
def _get(self, key: str) -> Any: ...
7173
def __setitem__(self, key: str, val: Any) -> None: ...
7274
def __getitem__(self, key: str) -> Any: ...
7375
def __iter__(self) -> Generator[str, None, None]: ...

lib/matplotlib/_type1font.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
v1.1, 1993. ISBN 0-201-57044-0.
2222
"""
2323

24+
from __future__ import annotations
25+
2426
import binascii
2527
import functools
2628
import logging
2729
import re
2830
import string
2931
import struct
32+
import typing as T
3033

3134
import numpy as np
3235

@@ -171,7 +174,7 @@ def value(self):
171174
return float(self.raw)
172175

173176

174-
def _tokenize(data: bytes, skip_ws: bool):
177+
def _tokenize(data: bytes, skip_ws: bool) -> T.Generator[_Token, int, None]:
175178
"""
176179
A generator that produces _Token instances fro EDBE m Type-1 font code.
177180
@@ -194,7 +197,7 @@ def _tokenize(data: bytes, skip_ws: bool):
194197
hex_re = re.compile(r'^<[0-9a-fA-F\0\t\r\f\n ]*>$')
195198
oct_re = re.compile(r'[0-7]{1,3}')
196199
pos = 0
197-
next_binary = None
200+
next_binary: int | None = None
198201

199202
while pos < len(text):
200203
if next_binary is not None:

lib/matplotlib/patheffects.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Normal(AbstractPathEffect): ...
5555
class Stroke(AbstractPathEffect):
5656
def __init__(self, offset: tuple[float, float] = ..., **kwargs) -> None: ...
5757
# rgbFace becomes non-optional
58-
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore
58+
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override]
5959

6060
class withStroke(Stroke): ...
6161

@@ -69,7 +69,7 @@ class SimplePatchShadow(AbstractPathEffect):
6969
**kwargs
7070
) -> None: ...
7171
# rgbFace becomes non-optional
72-
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore
72+
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override]
7373

7474
class withSimplePatchShadow(SimplePatchShadow): ...
7575

@@ -83,13 +83,13 @@ class SimpleLineShadow(AbstractPathEffect):
8383
**kwargs
8484
) -> None: ...
8585
# rgbFace becomes non-optional
86-
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore
86+
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override]
8787

8888
class PathPatchEffect(AbstractPathEffect):
8989
patch: Patch
9090
def __init__(self, offset: tuple[float, float] = ..., **kwargs) -> None: ...
9191
# rgbFace becomes non-optional
92-
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore
92+
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override]
9393

9494
class TickedStroke(AbstractPathEffect):
9595
def __init__(
@@ -101,6 +101,6 @@ class TickedStroke(AbstractPathEffect):
101101
**kwargs
102102
) -> None: ...
103103
# rgbFace becomes non-optional
104-
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore
104+
def draw_path(self, renderer: RendererBase, gc: GraphicsContextBase, tpath: Path, affine: Transform, rgbFace: ColorType) -> None: ... # type: ignore[override]
105105

106106
class withTickedStroke(TickedStroke): ...

lib/matplotlib/projections/__init__.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
from .geo import AitoffAxes, HammerAxes, LambertAxes, MollweideAxes
2-
from .polar import PolarAxes
1+
from .geo import (
2+
AitoffAxes as AitoffAxes,
3+
HammerAxes as HammerAxes,
4+
LambertAxes as LambertAxes,
5+
MollweideAxes as MollweideAxes,
6+
)
7+
from .polar import PolarAxes as PolarAxes
38
from ..axes import Axes
49

510
class ProjectionRegistry:

lib/matplotlib/pyplot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
from matplotlib.artist import Artist
7070
from matplotlib.axes import Axes
7171
from matplotlib.axes import Subplot # noqa: F401
72-
from matplotlib.projections import PolarAxes # type: ignore
72+
from matplotlib.projections import PolarAxes
7373
from matplotlib import mlab # for detrend_none, window_hanning
7474
from matplotlib.scale import get_scale_names # noqa: F401
7575

@@ -224,7 +224,7 @@ def install_repl_displayhook() -> None:
224224
ip.events.register("post_execute", _draw_all_if_interactive)
225225
_REPL_DISPLAYHOOK = _ReplDisplayHook.IPYTHON
226226

227-
from IPython.core.pylabtools import backend2gui # type: ignore
227+
from IPython.core.pylabtools import backend2gui
228228
# trigger IPython's eventloop integration, if available
229229
ipython_gui_name = backend2gui.get(get_backend())
230230
if ipython_gui_name:
@@ -235,7 +235,7 @@ def uninstall_repl_displayhook() -> None:
235235
"""Disconnect from the display hook of the current shell."""
236236
global _REPL_DISPLAYHOOK
237237
if _REPL_DISPLAYHOOK is _ReplDisplayHook.IPYTHON:
238-
from IPython import get_ipython # type: ignore
238+
from IPython import get_ipython
239239
ip = get_ipython()
240240
ip.events.unregister("post_execute", _draw_all_if_interactive)
241241
_REPL_DISPLAYHOOK = _ReplDisplayHook.NONE
@@ -274,7 +274,7 @@ def _get_backend_mod() -> type[matplotlib.backend_bases._Backend]:
274274
# Use rcParams._get("backend") to avoid going through the fallback
275275
# logic (which will (re)import pyplot and then call switch_backend if
276276
# we need to resolve the auto sentinel)
277-
switch_backend(rcParams._get("backend")) # type: ignore[attr-defined]
277+
switch_backend(rcParams._get("backend"))
278278
return cast(type[matplotlib.backend_bases._Backend], _backend_mod)
279279

280280

@@ -744,7 +744,7 @@ def xkcd(
744744
"xkcd mode is not compatible with text.usetex = True")
745745

746746
stack = ExitStack()
747-
stack.callback(dict.update, rcParams, rcParams.copy()) # type: ignore
747+
stack.callback(dict.update, rcParams, rcParams.copy()) # type: ignore[arg-type]
748748

749749
from matplotlib import patheffects
750750
rcParams.update({
@@ -2501,10 +2501,10 @@ def polar(*args, **kwargs) -> list[Line2D]:
25012501
# requested, ignore rcParams['backend'] and force selection of a backend that
25022502
# is compatible with the current running interactive framework.
25032503
if (rcParams["backend_fallback"]
2504-
and rcParams._get_backend_or_none() in ( # type: ignore
2504+
and rcParams._get_backend_or_none() in ( # type: ignore[attr-defined]
25052505
set(rcsetup.interactive_bk) - {'WebAgg', 'nbAgg'})
2506-
and cbook._get_running_interactive_framework()): # type: ignore
2507-
rcParams._set("backend", rcsetup._auto_backend_sentinel) # type: ignore
2506+
and cbook._get_running_interactive_framework()):
2507+
rcParams._set("backend", rcsetup._auto_backend_sentinel)
25082508

25092509
# fmt: on
25102510

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ convention = "numpy"
208208

209209
[tool.mypy]
210210
ignore_missing_imports = true
211+
enable_error_code = [
212+
"ignore-without-code",
213+
"redundant-expr",
214+
"truthy-bool",
215+
]
211216
enable_incomplete_feature = [
212217
"Unpack",
213218
]
@@ -227,6 +232,11 @@ exclude = [
227232
# stubtest will import and run, opening a figure if not excluded
228233
".*/tinypages"
229234
]
235+
files = [
236+
"lib/matplotlib",
237+
]
238+
follow_imports = "silent"
239+
warn_unreachable = true
230240

231241
[tool.rstcheck]
232242
ignore_directives = [

0 commit comments

Comments
 (0)
0