@@ -1256,24 +1256,6 @@ def _label_from_arg(y, default_name):
12561256 return None
12571257
12581258
1259- _DATA_DOC_TITLE = """
1260-
1261- Notes
1262- -----
1263- """
1264-
1265- _DATA_DOC_APPENDIX = """
1266-
1267- .. note::
1268- In addition to the above described arguments, this function can take
1269- a *data* keyword argument. If such a *data* argument is given,
1270- {replaced}
1271-
1272- Objects passed as **data** must support item access (``data[s]``) and
1273- membership test (``s in data``).
1274- """
1275-
1276-
12771259def _add_data_doc (docstring , replace_names ):
12781260 """
12791261 Add documentation for a *data* field to the given docstring.
@@ -1296,17 +1278,35 @@ def _add_data_doc(docstring, replace_names):
12961278 or replace_names is not None and len (replace_names ) == 0 ):
12971279 return docstring
12981280 docstring = inspect .cleandoc (docstring )
1299- repl = (
1300- (" every other argument can also be string ``s``, which is\n "
1301- " interpreted as ``data[s]`` (unless this raises an exception)." )
1302- if replace_names is None else
1303- (" the following arguments can also be string ``s``, which is\n "
1304- " interpreted as ``data[s]`` (unless this raises an exception):\n "
1305- " " + ", " .join (map ("*{}*" .format , replace_names ))) + "." )
1306- addendum = _DATA_DOC_APPENDIX .format (replaced = repl )
1307- if _DATA_DOC_TITLE not in docstring :
1308- addendum = _DATA_DOC_TITLE + addendum
1309- return docstring + addendum
1281+
1282+ data_doc = ("""\
1283+ If given, all parameters also accept a string ``s``, which is
1284+ interpreted as ``data[s]`` (unless this raises an exception).
1285+
1286+ Objects passed as **data** must support item access (``data[s]``) and
1287+ membership test (``s in data``)."""
1288+ if replace_names is None else ("""\
1289+ If given, the following parameters also accept a string ``s``, which
1290+ is interpreted as ``data[s]`` (unless this raises an exception):
1291+
1292+ {names}
1293+
1294+ Objects passed as **data** must support item access (``data[s]``) and
1295+ membership test (``s in data``).""" .format (
1296+ names = ", " .join (map ("*{}*" .format , replace_names )))
1297+ )
1298+ )
1299+ # using string replacement instead of formatting has the advantages
1300+ # 1) simpler indent handling
1301+ # 2) prevent problems with formatting characters '{', '%' in the docstring
1302+ if _log .level <= logging .DEBUG :
1303+ # test_data_parameter_replacement() tests against these log messages
1304+ # make sure to keep message and test in sync
1305+ if "data : indexable object, optional" not in docstring :
1306+ _log .debug ("data parameter docstring error: no data parameter" )
1307+ if 'DATA_PARAMETER_PLACEHOLDER' not in docstring :
1308+ _log .debug ("data parameter docstring error: missing placeholder" )
1309+ return docstring .replace (' DATA_PARAMETER_PLACEHOLDER' , data_doc )
13101310
13111311
13121312def _preprocess_data (func = None , * , replace_names = None , label_namer = None ):
0 commit comments