Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitdee7357

Browse files
authored
Merge pull request#24976 from ksunden/mypy-gradual
Initial implementation of type stubs (mypy/PEP484)
2 parents76f7545 +bd4469d commitdee7357

File tree

112 files changed

+12623
-515
lines changed

Some content is hidden

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

112 files changed

+12623
-515
lines changed

‎.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ exclude_lines =
1212
def __str__
1313
def __repr__
1414
if__name__ == .__main__.:
15+
if TYPE_CHECKING:
16+
if typing.TYPE_CHECKING:

‎.github/workflows/mypy-stubtest.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name:Mypy Stubtest
3+
on:[pull_request]
4+
5+
permissions:
6+
contents:read
7+
checks:write
8+
9+
jobs:
10+
mypy-stubtest:
11+
name:mypy-stubtest
12+
runs-on:ubuntu-latest
13+
steps:
14+
-uses:actions/checkout@v3
15+
16+
-name:Set up Python 3
17+
uses:actions/setup-python@v4
18+
with:
19+
python-version:3.9
20+
21+
-name:Install mypy
22+
run:|
23+
pip3 install -r requirements/testing/mypy.txt -r requirements/testing/all.txt
24+
pip3 install .
25+
26+
-name:Run mypy stubtest
27+
run:|
28+
# the ignore missing imports can be removed when typed cycler is released and used
29+
MPLBACKEND=agg python -m mypy.stubtest matplotlib --mypy-config-file pyproject.toml \
30+
--allowlist ci/mypy-stubtest-allowlist.txt

‎.github/workflows/reviewdog.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,40 @@ jobs:
3838
flake8 --docstring-convention=all | \
3939
reviewdog -f=pep8 -name=flake8 \
4040
-tee -reporter=github-check -filter-mode nofilter
41+
mypy:
42+
name:mypy
43+
runs-on:ubuntu-latest
44+
steps:
45+
-uses:actions/checkout@v3
46+
47+
-name:Set up Python 3
48+
uses:actions/setup-python@v4
49+
with:
50+
python-version:3.9
51+
52+
-name:Install mypy
53+
run:pip3 install -r requirements/testing/mypy.txt -r requirements/testing/all.txt
54+
55+
-name:Set up reviewdog
56+
run:|
57+
mkdir -p "$HOME/bin"
58+
curl -sfL \
59+
https://github.com/reviewdog/reviewdog/raw/master/install.sh | \
60+
sh -s -- -b "$HOME/bin"
61+
echo "$HOME/bin" >> $GITHUB_PATH
62+
63+
-name:Run mypy
64+
env:
65+
REVIEWDOG_GITHUB_API_TOKEN:${{ secrets.GITHUB_TOKEN }}
66+
run:|
67+
set -o pipefail
68+
# The --ignore-missing-imports can be removed when typed cycler is released and used
69+
mypy --config pyproject.toml lib/matplotlib \
70+
--ignore-missing-imports \
71+
--follow-imports silent | \
72+
reviewdog -f=mypy -name=mypy \
73+
-tee -reporter=github-check -filter-mode nofilter
74+
4175
4276
eslint:
4377
name:eslint

‎ci/mypy-stubtest-allowlist.txt

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# Non-typed (and private) modules/functions
2+
matplotlib.backends.*
3+
matplotlib.tests.*
4+
matplotlib.pylab.*
5+
matplotlib._.*
6+
matplotlib.rcsetup._listify_validator
7+
matplotlib.rcsetup._validate_linestyle
8+
matplotlib.ft2font.*
9+
matplotlib.testing.*
10+
matplotlib.sphinxext.*
11+
12+
# set methods have heavy dynamic usage of **kwargs, with differences for subclasses
13+
# which results in technically inconsistent signatures, but not actually a problem
14+
matplotlib.*\.set$
15+
16+
# Typed inline, inconsistencies largely due to imports
17+
matplotlib.pyplot.*
18+
matplotlib.typing.*
19+
20+
# _preprocess_data arg decorator
21+
matplotlib.axes.*Axes.acorr
22+
matplotlib.axes.*Axes.angle_spectrum
23+
matplotlib.axes.*Axes.bar
24+
matplotlib.axes.*Axes.barbs
25+
matplotlib.axes.*Axes.boxplot
26+
matplotlib.axes.*Axes.broken_barh
27+
matplotlib.axes.*Axes.cohere
28+
matplotlib.axes.*Axes.contour
29+
matplotlib.axes.*Axes.contourf
30+
matplotlib.axes.*Axes.csd
31+
matplotlib.axes.*Axes.ecdf
32+
matplotlib.axes.*Axes.errorbar
33+
matplotlib.axes.*Axes.eventplot
34+
matplotlib.axes.*Axes.fill_between
35+
matplotlib.axes.*Axes.fill_betweenx
36+
matplotlib.axes.*Axes.hexbin
37+
matplotlib.axes.*Axes.hist
38+
matplotlib.axes.*Axes.hist2d
39+
matplotlib.axes.*Axes.hlines
40+
matplotlib.axes.*Axes.imshow
41+
matplotlib.axes.*Axes.magnitude_spectrum
42+
matplotlib.axes.*Axes.pcolor
43+
matplotlib.axes.*Axes.pcolorfast
44+
matplotlib.axes.*Axes.pcolormesh
45+
matplotlib.axes.*Axes.phase_spectrum
46+
matplotlib.axes.*Axes.pie
47+
matplotlib.axes.*Axes.plot_date
48+
matplotlib.axes.*Axes.psd
49+
matplotlib.axes.*Axes.quiver
50+
matplotlib.axes.*Axes.scatter
51+
matplotlib.axes.*Axes.specgram
52+
matplotlib.axes.*Axes.stairs
53+
matplotlib.axes.*Axes.stem
54+
matplotlib.axes.*Axes.violinplot
55+
matplotlib.axes.*Axes.vlines
56+
matplotlib.axes.*Axes.xcorr
57+
58+
# Other decorator modifying signature (maybe investigate)
59+
matplotlib.axis.Axis.draw
60+
matplotlib.offsetbox.*Offset[Bb]ox.get_offset
61+
62+
# Inconsistent super/sub class signatures (other than just arg name)
63+
matplotlib.ticker.MultipleLocator.set_params
64+
matplotlib.text.Annotation.get_window_extent
65+
66+
# Inconsistent super/sub class parameter name (maybe rename for consistency)
67+
matplotlib.axis.Axis.set_clip_path
68+
matplotlib.axis.Tick.set_clip_path
69+
matplotlib.image.NonUniformImage.set_filternorm
70+
matplotlib.image.NonUniformImage.set_filterrad
71+
matplotlib.projections.geo.AitoffAxes.AitoffTransform.transform_non_affine
72+
matplotlib.projections.geo.AitoffAxes.InvertedAitoffTransform.transform_non_affine
73+
matplotlib.projections.geo.HammerAxes.HammerTransform.transform_non_affine
74+
matplotlib.projections.geo.HammerAxes.InvertedHammerTransform.transform_non_affine
75+
matplotlib.projections.geo.LambertAxes.InvertedLambertTransform.transform_non_affine
76+
matplotlib.projections.geo.LambertAxes.LambertTransform.transform_non_affine
77+
matplotlib.projections.geo.MollweideAxes.InvertedMollweideTransform.transform_non_affine
78+
matplotlib.projections.geo.MollweideAxes.MollweideTransform.transform_non_affine
79+
matplotlib.projections.polar.InvertedPolarTransform.transform_non_affine
80+
matplotlib.projections.polar.PolarTransform.transform_non_affine
81+
matplotlib.projections.polar.RadialLocator.nonsingular
82+
matplotlib.scale.AsinhTransform.transform_non_affine
83+
matplotlib.scale.InvertedAsinhTransform.transform_non_affine
84+
matplotlib.scale.InvertedSymmetricalLogTransform.transform_non_affine
85+
matplotlib.scale.LogisticTransform.transform_non_affine
86+
matplotlib.scale.LogitTransform.transform_non_affine
87+
matplotlib.scale.SymmetricalLogTransform.transform_non_affine
88+
matplotlib.table.Cell.set_transform
89+
matplotlib.ticker.LogLocator.nonsingular
90+
matplotlib.ticker.LogitLocator.nonsingular
91+
matplotlib.transforms.Affine2DBase.transform_affine
92+
matplotlib.transforms.AffineBase.transform_non_affine
93+
matplotlib.transforms.BlendedGenericTransform.transform_non_affine
94+
matplotlib.transforms.CompositeGenericTransform.transform_affine
95+
matplotlib.transforms.CompositeGenericTransform.transform_non_affine
96+
matplotlib.transforms.IdentityTransform.transform_affine
97+
matplotlib.transforms.IdentityTransform.transform_non_affine
98+
matplotlib.transforms.IdentityTransform.transform
99+
100+
# Stdlib/Enum considered inconsistent (no fault of ours, I don't think)
101+
matplotlib.backend_bases._Mode.__new__
102+
matplotlib.units.Number.__hash__
103+
104+
# Property read-write vs read-only weirdness, fix if possible
105+
matplotlib.offsetbox.DraggableBase.canvas
106+
matplotlib.offsetbox.DraggableBase.cids
107+
matplotlib.transforms.BboxTransform.is_separable
108+
matplotlib.transforms.BboxTransformFrom.is_separable
109+
matplotlib.transforms.BboxTransformTo.is_separable
110+
matplotlib.transforms.BlendedAffine2D.is_separable
111+
matplotlib.transforms.CompositeGenericTransform.is_separable
112+
matplotlib.transforms.TransformWrapper.input_dims
113+
matplotlib.transforms.TransformWrapper.is_separable
114+
matplotlib.transforms.TransformWrapper.output_dims
115+
116+
# 3.6 deprecations
117+
matplotlib.colorbar.Colorbar.__init__
118+
matplotlib.figure.Figure.callbacks
119+
matplotlib.figure.Figure.set_constrained_layout
120+
matplotlib.figure.Figure.set_constrained_layout_pads
121+
matplotlib.figure.Figure.set_tight_layout
122+
matplotlib.figure.SubFigure.callbacks
123+
124+
# 3.7 deprecations
125+
matplotlib.cm.register_cmap
126+
matplotlib.cm.unregister_cmap
127+
matplotlib.collections.PolyCollection.span_where
128+
matplotlib.gridspec.GridSpecBase.get_grid_positions
129+
matplotlib.widgets.Lasso.__init__
130+
matplotlib.widgets.PolygonSelector.__init__
131+
matplotlib.widgets.Slider.__init__
132+
matplotlib.widgets.RangeSlider.__init__
133+
matplotlib.widgets.TextBox.__init__
134+
matplotlib.widgets.Cursor.__init__
135+
matplotlib.widgets.MultiCursor.__init__
136+
matplotlib.widgets.SpanSelector.__init__
137+
matplotlib.widgets.ToolLineHandles.__init__
138+
matplotlib.widgets.ToolHandles.__init__
139+
matplotlib.widgets.LassoSelector.__init__
140+
matplotlib.widgets.MultiCursor.needclear
141+
142+
# 3.8 deprecations
143+
matplotlib.axes._base._AxesBase.get_tightbbox
144+
matplotlib.cbook.get_sample_data
145+
matplotlib.contour.ContourSet.allkinds
146+
matplotlib.contour.ContourSet.allsegs
147+
matplotlib.contour.ContourSet.tcolors
148+
matplotlib.contour.ContourSet.tlinewidths
149+
matplotlib.figure.FigureBase.get_tightbbox
150+
151+
# positional-only argument name lacking leading underscores
152+
matplotlib.axes._base._AxesBase.axis
153+
154+
# Aliases (dynamically generated, not type hinted)
155+
matplotlib.collections.Collection.get_dashes
156+
matplotlib.collections.Collection.get_ec
157+
matplotlib.collections.Collection.get_edgecolors
158+
matplotlib.collections.Collection.get_facecolors
159+
matplotlib.collections.Collection.get_fc
160+
matplotlib.collections.Collection.get_linestyles
161+
matplotlib.collections.Collection.get_linewidths
162+
matplotlib.collections.Collection.get_ls
163+
matplotlib.collections.Collection.get_lw
164+
matplotlib.collections.Collection.get_transOffset
165+
matplotlib.collections.Collection.set_aa
166+
matplotlib.collections.Collection.set_antialiaseds
167+
matplotlib.collections.Collection.set_dashes
168+
matplotlib.collections.Collection.set_ec
169+
matplotlib.collections.Collection.set_edgecolors
170+
matplotlib.collections.Collection.set_facecolors
171+
matplotlib.collections.Collection.set_fc
172+
matplotlib.collections.Collection.set_linestyles
173+
matplotlib.collections.Collection.set_linewidths
174+
matplotlib.collections.Collection.set_ls
175+
matplotlib.collections.Collection.set_lw
176+
matplotlib.collections.Collection.set_transOffset
177+
matplotlib.lines.Line2D.get_aa
178+
matplotlib.lines.Line2D.get_c
179+
matplotlib.lines.Line2D.get_ds
180+
matplotlib.lines.Line2D.get_ls
181+
matplotlib.lines.Line2D.get_lw
182+
matplotlib.lines.Line2D.get_mec
183+
matplotlib.lines.Line2D.get_mew
184+
matplotlib.lines.Line2D.get_mfc
185+
matplotlib.lines.Line2D.get_mfcalt
186+
matplotlib.lines.Line2D.get_ms
187+
matplotlib.lines.Line2D.set_aa
188+
matplotlib.lines.Line2D.set_c
189+
matplotlib.lines.Line2D.set_ds
190+
matplotlib.lines.Line2D.set_ls
191+
matplotlib.lines.Line2D.set_lw
192+
matplotlib.lines.Line2D.set_mec
193+
matplotlib.lines.Line2D.set_mew
194+
matplotlib.lines.Line2D.set_mfc
195+
matplotlib.lines.Line2D.set_mfcalt
196+
matplotlib.lines.Line2D.set_ms
197+
matplotlib.patches.Patch.get_aa
198+
matplotlib.patches.Patch.get_ec
199+
matplotlib.patches.Patch.get_fc
200+
matplotlib.patches.Patch.get_ls
201+
matplotlib.patches.Patch.get_lw
202+
matplotlib.patches.Patch.set_aa
203+
matplotlib.patches.Patch.set_ec
204+
matplotlib.patches.Patch.set_fc
205+
matplotlib.patches.Patch.set_ls
206+
matplotlib.patches.Patch.set_lw
207+
matplotlib.text.Text.get_c
208+
matplotlib.text.Text.get_family
209+
matplotlib.text.Text.get_font
210+
matplotlib.text.Text.get_font_properties
211+
matplotlib.text.Text.get_ha
212+
matplotlib.text.Text.get_name
213+
matplotlib.text.Text.get_size
214+
matplotlib.text.Text.get_style
215+
matplotlib.text.Text.get_va
216+
matplotlib.text.Text.get_variant
217+
matplotlib.text.Text.get_weight
218+
matplotlib.text.Text.set_c
219+
matplotlib.text.Text.set_family
220+
matplotlib.text.Text.set_font
221+
matplotlib.text.Text.set_font_properties
222+
matplotlib.text.Text.set_ha
223+
matplotlib.text.Text.set_ma
224+
matplotlib.text.Text.set_name
225+
matplotlib.text.Text.set_size
226+
matplotlib.text.Text.set_stretch
227+
matplotlib.text.Text.set_style
228+
matplotlib.text.Text.set_va
229+
matplotlib.text.Text.set_variant
230+
matplotlib.text.Text.set_weight
231+
matplotlib.axes._base._AxesBase.get_fc
232+
matplotlib.axes._base._AxesBase.set_fc
233+
234+
# Other dynamic python behaviors not type hinted
235+
matplotlib.projections.polar.PolarAxes.InvertedPolarTransform
236+
matplotlib.projections.polar.PolarAxes.PolarAffine
237+
matplotlib.projections.polar.PolarAxes.PolarTransform
238+
matplotlib.projections.polar.PolarAxes.RadialLocator
239+
matplotlib.projections.polar.PolarAxes.ThetaFormatter
240+
matplotlib.projections.polar.PolarAxes.ThetaLocator
241+
matplotlib.rcsetup.defaultParams
242+
243+
# Maybe should be abstractmethods, required for subclasses, stubs define once
244+
matplotlib.tri.*TriInterpolator.__call__
245+
matplotlib.tri.*TriInterpolator.gradient
246+
247+
# Functionally a method call, but actually a class instance, type hinted as former
248+
matplotlib.rcsetup.validate_fillstyle
249+
250+
# C-defined method without docstring indicating signature
251+
matplotlib.transforms.count_bboxes_overlapping_bbox
252+
matplotlib.transforms.update_path_extents
253+
254+
# TypeVar used only in type hints
255+
matplotlib.backend_bases.FigureCanvasBase._T
256+
matplotlib.backend_managers.ToolManager._T
257+
matplotlib.spines.Spine._T

‎doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ Alphabetical list of modules:
153153
transformations.rst
154154
tri_api.rst
155155
type1font.rst
156+
typing_api.rst
156157
units_api.rst
157158
widgets_api.rst
158159
_api_api.rst
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Provisional support for PEP484 Type Hint Annotations
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
New public API should be type hinted in ``.pyi`` stub files (except ``pyplot`` and tests
5+
which are typed in-line).
6+
Tests should be type hinted minimally, essentially only when ``mypy`` generates errors.
7+
8+
CI and configuration for running ``mypy`` have been added.
9+
10+
11+
Generation of ``pyplot.py`` requires ``black``
12+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
14+
The autogenerated portions of ``pyplot.py`` use ``black`` autoformatting to ensure
15+
syntax-correct, readable output code.
16+
17+
As such ``black`` is now a development and test requirement (for the test which
18+
regenerates ``pyplot``).

‎doc/api/typing_api.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*********************
2+
``matplotlib.typing``
3+
*********************
4+
5+
..autodata::matplotlib.typing.ColorType
6+
..autodata::matplotlib.typing.ColourType
7+
..autodata::matplotlib.typing.LineStyleType
8+
..autodata::matplotlib.typing.DrawStyleType
9+
..autodata::matplotlib.typing.MarkEveryType
10+
..autodata::matplotlib.typing.FillStyleType
11+
..autodata::matplotlib.typing.RcStyleType

‎doc/devel/coding_guide.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ rules before submitting a pull request:
8282
by the contributor's initials. (see:file:`doc/api/api_changes.rst` for more
8383
information)
8484

85+
* If you add new public API or change public API, update or add the
86+
corresponding type hints. Most often this is found in the corresponding
87+
``.pyi`` file for the ``.py`` file which was edited. Changes in ``pyplot.py``
88+
are type hinted inline.
89+
8590
* See below for additional points about:ref:`keyword-argument-processing`, if
8691
applicable for your pull request.
8792

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp