Use ruff to format code snippets in docstrings and remove blackdoc #2909
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
Since ruff v0.1.8, ruff can format code snippets in docstrings, which can replace the
blackdoctool we're using. See https://astral.sh/blog/ruff-v0.1.8#formatting-code-snippets-in-docstrings for more details. Currently the feature is disabled by default and can be enabled by settingdocstring-code-format = true.Another important setting is
docstring-code-line-length, which can be either an integer value ordynamic(default).I'm still debating what's the most reasonable value for
docstring-code-line-length. Here is an example to clarify the differences between"dynamic"and a fixed integer (e.g.,79or88).docstring-code-line-length = 88gives:docstring-code-line-length = "dynamic"gives:Edit:
docstring-code-line-lengthmeans the actual line length can be longer than 88 characters, which won't work well when viewing the docstrings in text editors/IDEs/Notebooks (see Change the line length limit of docstrings to 88 characters #962).docstring-code-line-length="dynamic"means the doc length won't exceed 88-charcters, which works well in any environment (Change the line length limit of docstrings to 88 characters #962 (comment)).Related to #962 and #2741.