Skip to content

Commit 2acce77

Browse files
datapythonistajreback
authored andcommitted
DOC: Adding prefix to autosummary of deprecated docstrings (#19220)
1 parent fe0861e commit 2acce77

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

doc/source/conf.py

+23
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
import inspect
1818
import importlib
19+
from sphinx.ext.autosummary import _import_by_name
1920
import warnings
2021

2122

@@ -47,6 +48,10 @@
4748

4849
])
4950

51+
# numpydoc is available in the sphinxext directory, and can't be imported
52+
# until sphinxext is available in the Python path
53+
from numpydoc.docscrape import NumpyDocString
54+
5055
# -- General configuration -----------------------------------------------
5156

5257
# Add any Sphinx extension module names here, as strings. They can be
@@ -506,9 +511,27 @@ def _replace_pandas_items(self, display_name, sig, summary, real_name):
506511
summary = 'Series plotting accessor and method'
507512
return (display_name, sig, summary, real_name)
508513

514+
@staticmethod
515+
def _is_deprecated(real_name):
516+
try:
517+
obj, parent, modname = _import_by_name(real_name)
518+
except ImportError:
519+
return False
520+
doc = NumpyDocString(obj.__doc__ or '')
521+
summary = ''.join(doc['Summary'] + doc['Extended Summary'])
522+
return '.. deprecated::' in summary
523+
524+
def _add_deprecation_prefixes(self, items):
525+
for item in items:
526+
display_name, sig, summary, real_name = item
527+
if self._is_deprecated(real_name):
528+
summary = '(DEPRECATED) %s' % summary
529+
yield display_name, sig, summary, real_name
530+
509531
def get_items(self, names):
510532
items = Autosummary.get_items(self, names)
511533
items = [self._replace_pandas_items(*item) for item in items]
534+
items = list(self._add_deprecation_prefixes(items))
512535
return items
513536

514537

0 commit comments

Comments
 (0)