Skip to content

Commit 9427e15

Browse files
committed
fmt_docstrings: Support raw curly braces in docstrings using str.format_map
1 parent dc6fd38 commit 9427e15

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pygmt/helpers/decorators.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,21 @@ def fmt_docstring(module_func):
441441
- R = region
442442
<BLANKLINE>
443443
""" # noqa: D410,D411
444-
filler_text = {}
444+
445+
class _Placeholder(dict):
446+
"""
447+
A dict subclass that allows missing placeholders in docstrings.
448+
449+
Related to https://github.com/GenericMappingTools/pygmt/issues/3815.
450+
"""
451+
452+
def __missing__(self, key):
453+
"""
454+
Return "{key}" for a missing key.
455+
"""
456+
return "{" + key + "}"
457+
458+
filler_text = _Placeholder()
445459

446460
if hasattr(module_func, "aliases"):
447461
aliases = ["**Aliases:**\n"]
@@ -467,8 +481,7 @@ def fmt_docstring(module_func):
467481
# Dedent the docstring to make it all match the option text.
468482
docstring = textwrap.dedent(module_func.__doc__)
469483

470-
module_func.__doc__ = docstring.format(**filler_text)
471-
484+
module_func.__doc__ = docstring.format_map(filler_text)
472485
return module_func
473486

474487

0 commit comments

Comments
 (0)