Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt_docstring: Allow raw curly braces {} to avoid KeyError #3815

Open
seisman opened this issue Feb 18, 2025 · 0 comments
Open

fmt_docstring: Allow raw curly braces {} to avoid KeyError #3815

seisman opened this issue Feb 18, 2025 · 0 comments
Labels
discussions Need more discussion before taking further actions

Comments

@seisman
Copy link
Member

seisman commented Feb 18, 2025

Description of the desired feature

The @fmt_docstring decorator is responsible for inserting common docstrings into placeholders. While it works well in general, it currently raises a KeyError when encountering an undefined placeholder. For example, in #3811, we're writing equations in ReST syntax:

:math:`mantissa * 10 ^ {exponent}`

and it reports KeyError: exponent because we don't have exponent defined in COMMON_STRINGS. This requires us to escape such placeholders by writing the equation like

:math:`mantissa * 10 ^ {{exponent}}`

which is inconvenient, and sometimes we may forget to do it and then see the KeyError exception surprisingly.

Current Behavior:

  • If {exponent} (or any other undefined placeholder) appears in a docstring, fmt_docstring raises a KeyError.
  • To work around this, users must write {{exponent}} to ensure the curly braces are preserved in the final docstring.

Expected Behavior:

  • {exponent} (or any other undefined placeholder) should be treated as a literal string unless it matches a defined common docstring key.
  • Users should not have to manually escape curly braces unless explicitly required.

Pros

  1. No need to escape curly braces, especially for equations
  2. The raw docstrings are more readable

Cons

If there are any typos in common placeholder (e.g., projection typed as projecti), then the literal string {projecti} is shown in the HTML documentation. It no longer raises a KeyError exception, and we may miss the typo.

Are you willing to help implement and maintain this feature?

Yes

@seisman seisman added the discussions Need more discussion before taking further actions label Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussions Need more discussion before taking further actions
Projects
None yet
Development

No branches or pull requests

1 participant