Skip to content

Commit c50845b

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

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pygmt/helpers/decorators.py

Lines changed: 10 additions & 3 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,6 +443,13 @@ def fmt_docstring(module_func):
442443
<BLANKLINE>
443444
""" # noqa: D410,D411
444445

446+
class _MyTemplate(string.Template):
447+
"""
448+
A Template subclass that allows missing placeholders in docstrings.
449+
"""
450+
451+
delimiter = ""
452+
445453
class _Placeholder(dict):
446454
"""
447455
A dict subclass that allows missing placeholders in docstrings.
@@ -455,8 +463,7 @@ def __missing__(self, key):
455463
"""
456464
return "{" + key + "}"
457465

458-
filler_text = _Placeholder()
459-
466+
filler_text = {}
460467
if hasattr(module_func, "aliases"):
461468
aliases = ["**Aliases:**\n"]
462469
aliases.append(".. hlist::")
@@ -481,7 +488,7 @@ def __missing__(self, key):
481488
# Dedent the docstring to make it all match the option text.
482489
docstring = textwrap.dedent(module_func.__doc__)
483490

484-
module_func.__doc__ = docstring.format_map(filler_text)
491+
module_func.__doc__ = _MyTemplate(docstring).safe_substitute(**filler_text)
485492
return module_func
486493

487494

0 commit comments

Comments
 (0)