ruff/crates/ruff_python_formatter/tests/snapshots
Andrew Gallant d9845a2628
format doctests in docstrings (#8811)
## Summary

This PR adds opt-in support for formatting doctests in docstrings. This
reflects initial support and it is intended to add support for Markdown
and reStructuredText Python code blocks in the future. But I believe
this PR lays the groundwork, and future additions for Markdown and reST
should be less costly to add.

It's strongly recommended to review this PR commit-by-commit. The last
few commits in particular implement the bulk of the work here and
represent the denser portions.

Some things worth mentioning:

* The formatter is itself not perfect, and it is possible for it to
produce invalid Python code. Because of this, reformatted code snippets
are checked for Python validity. If they aren't valid, then we
(unfortunately silently) bail on formatting that code snippet.
* There are a couple places where it would be nice to at least warn the
user that doctest formatting failed, but it wasn't clear to me what the
best way to do that is.
* I haven't yet run this in anger on a real world code base. I think
that should happen before merging.

Closes #7146 

## Test Plan

* [x] Pass the local test suite.
* [x] Scrutinize ecosystem changes.
* [x] Run this formatter on extant code and scrutinize the results.
(e.g., CPython, numpy.)
2023-11-27 11:14:55 -05:00
..
black_compatibility@conditional_expression.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__blackd_diff.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__debug_visitor.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__decorators.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__docstring_no_string_normalization.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__docstring_preview_no_string_normalization.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__force_pyi.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__long_strings_flag_disabled.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__power_op_newline.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@miscellaneous__string_quotes.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@py_38__pep_572_remove_parens.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@py_310__pattern_matching_extras.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@py_310__pattern_matching_style.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@py_310__pep_572_py310.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@raw_docstring.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__comment_after_escaped_newline.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__comments2.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__comments6.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__comments9.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__composition.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__composition_no_trailing_comma.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__docstring_preview.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__expression.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__fmtonoff.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__fmtonoff4.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__fmtonoff5.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__fmtpass_imports.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__fmtskip5.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__function.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__function2.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__ignore_pyi.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__multiline_consecutive_open_parentheses_ignore.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__remove_await_parens.py.snap Fix instability with await fluent style (#8676) 2023-11-17 12:24:19 -05:00
black_compatibility@simple_cases__remove_except_parens.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__remove_for_brackets.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__return_annotation_brackets.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__torture.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__trailing_commas_in_leading_parts.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
black_compatibility@simple_cases__tupleassign.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@carriage_return__string.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@docstring.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@docstring_code_examples.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@docstring_code_examples_crlf.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@empty_multiple_trailing_newlines.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@empty_now_newline.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@empty_trailing_newline.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@empty_whitespace.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__annotated_assign.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__attribute.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__await.py.snap Fix instability with await fluent style (#8676) 2023-11-17 12:24:19 -05:00
format@expression__binary.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__binary_implicit_string.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__binary_pow_spacing.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__boolean_operation.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__bytes.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@expression__call.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__compare.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__dict.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__dict_comp.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__fstring.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__generator_exp.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__if.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__lambda.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__list.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__list_comp.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__named_expr.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__number.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__optional_parentheses_comments.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__set_comp.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__slice.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__split_empty_brackets.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__starred.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__string.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@expression__subscript.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__tuple.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__unary.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__unsplittable.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__yield.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@expression__yield_from.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__comments.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__empty_file.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__fmt_off_docstring.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@fmt_on_off__fmt_off_unclosed_deep_nested_trailing_comment.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__fmt_off_unclosed_trailing_comment.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__form_feed.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__indent.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@fmt_on_off__last_statement.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__mixed_space_and_tab.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@fmt_on_off__newlines.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__no_fmt_on.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__off_on_off_on.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__simple.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__trailing_comments.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__trailing_semicolon.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_on_off__yapf.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_skip__decorators.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_skip__docstrings.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_skip__match.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_skip__or_else.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_skip__parentheses.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_skip__trailing_semi.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@fmt_skip__type_params.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@form_feed.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@module_dangling_comment1.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@module_dangling_comment2.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@newlines.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@newlines.pyi.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@parentheses__call_chains.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@parentheses__expression_parentheses_comments.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@parentheses__nested.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@parentheses__opening_parentheses_comment_empty.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@parentheses__opening_parentheses_comment_value.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@preview.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@skip_magic_trailing_comma.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@statement__ann_assign.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__assert.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__assign.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__aug_assign.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__break.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__class_definition.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__delete.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__ellipsis.pyi.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__for.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__function.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__global.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__if.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__import.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__import_from.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__match.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__module_comment.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__nonlocal.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__raise.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__return.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__return_annotation.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__top_level.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__top_level.pyi.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__try.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__type_alias.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__while.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@statement__with.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@stub_files__comments.pyi.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@stub_files__nesting.pyi.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@stub_files__suite.pyi.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@stub_files__top_level.pyi.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@tab_width.py.snap format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
format@trailing_comments.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
format@trivia.py.snap Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00