Skip to content

Commit f44e356

Browse files
committed
Subclass string.Template instead
1 parent 89dbcee commit f44e356

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

pygmt/helpers/decorators.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import functools
9+
import string
910
import textwrap
1011
import warnings
1112
from inspect import Parameter, signature
@@ -442,21 +443,14 @@ def fmt_docstring(module_func):
442443
<BLANKLINE>
443444
""" # noqa: D410,D411
444445

445-
class _Placeholder(dict):
446+
class _MyTemplate(string.Template):
446447
"""
447-
A dict subclass that allows missing placeholders in docstrings.
448-
449-
Related to https://github.com/GenericMappingTools/pygmt/issues/3815.
448+
A Template subclass that allows missing placeholders in docstrings.
450449
"""
451450

452-
def __missing__(self, key):
453-
"""
454-
Return "{key}" for a missing key.
455-
"""
456-
return "{" + key + "}"
457-
458-
filler_text = _Placeholder()
451+
delimiter = "" # Default delimiter is $.
459452

453+
filler_text = {}
460454
if hasattr(module_func, "aliases"):
461455
aliases = ["**Aliases:**\n"]
462456
aliases.append(".. hlist::")
@@ -481,7 +475,7 @@ def __missing__(self, key):
481475
# Dedent the docstring to make it all match the option text.
482476
docstring = textwrap.dedent(module_func.__doc__)
483477

484-
module_func.__doc__ = docstring.format_map(filler_text)
478+
module_func.__doc__ = _MyTemplate(docstring).safe_substitute(**filler_text)
485479
return module_func
486480

487481

0 commit comments

Comments
 (0)