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

Commitf4f9528

Browse files
authored
Merge pull request#24000 from timhoffm/pyplot-test
Generalize validation that pyplot commands are documented
2 parents9bcdd60 +352bb1f commitf4f9528

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``matplotlib.pyplot.get_plot_commands``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... is a pending deprecation. This is considered internal and no end-user
5+
should need it.

‎lib/matplotlib/pyplot.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,20 +2028,23 @@ def thetagrids(angles=None, labels=None, fmt=None, **kwargs):
20282028
returnlines,labels
20292029

20302030

2031-
_NON_PLOT_COMMANDS= {
2032-
'connect','disconnect','get_current_fig_manager','ginput',
2033-
'new_figure_manager','waitforbuttonpress'}
2034-
2035-
2031+
@_api.deprecated("3.7",pending=True)
20362032
defget_plot_commands():
20372033
"""
20382034
Get a sorted list of all of the plotting commands.
20392035
"""
2036+
NON_PLOT_COMMANDS= {
2037+
'connect','disconnect','get_current_fig_manager','ginput',
2038+
'new_figure_manager','waitforbuttonpress'}
2039+
return (namefornamein_get_pyplot_commands()
2040+
ifnamenotinNON_PLOT_COMMANDS)
2041+
2042+
2043+
def_get_pyplot_commands():
20402044
# This works by searching for all functions in this module and removing
20412045
# a few hard-coded exclusions, as well as all of the colormap-setting
20422046
# functions, and anything marked as private with a preceding underscore.
2043-
exclude= {'colormaps','colors','get_plot_commands',
2044-
*_NON_PLOT_COMMANDS,*colormaps}
2047+
exclude= {'colormaps','colors','get_plot_commands',*colormaps}
20452048
this_module=inspect.getmodule(get_plot_commands)
20462049
returnsorted(
20472050
nameforname,objinglobals().items()

‎lib/matplotlib/tests/test_pyplot.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
importdifflib
2-
importre
32

43
importnumpyasnp
54
importsubprocess
@@ -367,10 +366,42 @@ def test_doc_pyplot_summary():
367366
ifnotpyplot_docs.exists():
368367
pytest.skip("Documentation sources not available")
369368

370-
lines=pyplot_docs.read_text()
371-
m=re.search(r':nosignatures:\n\n(.*?)\n\n',lines,re.DOTALL)
372-
doc_functions=set(line.strip()forlineinm.group(1).split('\n'))
373-
plot_commands=set(plt.get_plot_commands())
369+
defextract_documented_functions(lines):
370+
"""
371+
Return a list of all the functions that are mentioned in the
372+
autosummary blocks contained in *lines*.
373+
374+
An autosummary block looks like this::
375+
376+
.. autosummary::
377+
:toctree: _as_gen
378+
:template: autosummary.rst
379+
:nosignatures:
380+
381+
plot
382+
plot_date
383+
384+
"""
385+
functions= []
386+
in_autosummary=False
387+
forlineinlines:
388+
ifnotin_autosummary:
389+
ifline.startswith(".. autosummary::"):
390+
in_autosummary=True
391+
else:
392+
ifnotlineorline.startswith(" :"):
393+
# empty line or autosummary parameter
394+
continue
395+
ifnotline[0].isspace():
396+
# no more indentation: end of autosummary block
397+
in_autosummary=False
398+
continue
399+
functions.append(line.strip())
400+
returnfunctions
401+
402+
lines=pyplot_docs.read_text().split("\n")
403+
doc_functions=set(extract_documented_functions(lines))
404+
plot_commands=set(plt._get_pyplot_commands())
374405
missing=plot_commands.difference(doc_functions)
375406
ifmissing:
376407
raiseAssertionError(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp