ruff_python_formatter: light refactoring of code snippet formatting in docstrings (#8950)
In the source of working on #8859, I made a number of smallish refactors to how code snippet formatting works. Most or all of these were motivated by writing in support for reStructuredText blocks. They have some fundamentally different requirements than doctests, and there are a lot more ways for reStructuredText blocks to become invalid. (Commit-by-commit review is recommended as the commit messages provide further context on each change. I split this off from ongoing work to make review more manageable.)
This commit is contained in:
@@ -4,6 +4,15 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/docstring_
|
||||
---
|
||||
## Input
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
@@ -336,6 +345,15 @@ preview = Disabled
|
||||
```
|
||||
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
@@ -671,6 +689,15 @@ preview = Disabled
|
||||
```
|
||||
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
@@ -1006,6 +1033,15 @@ preview = Disabled
|
||||
```
|
||||
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
@@ -1341,6 +1377,15 @@ preview = Disabled
|
||||
```
|
||||
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
@@ -1676,6 +1721,15 @@ preview = Disabled
|
||||
```
|
||||
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
@@ -2011,6 +2065,15 @@ preview = Disabled
|
||||
```
|
||||
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
@@ -2346,6 +2409,15 @@ preview = Disabled
|
||||
```
|
||||
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
@@ -2681,6 +2753,15 @@ preview = Disabled
|
||||
```
|
||||
|
||||
```python
|
||||
###############################################################################
|
||||
# DOCTEST CODE EXAMPLES
|
||||
#
|
||||
# This section shows examples of docstrings that contain code snippets in
|
||||
# Python's "doctest" format.
|
||||
#
|
||||
# See: https://docs.python.org/3/library/doctest.html
|
||||
###############################################################################
|
||||
|
||||
# The simplest doctest to ensure basic formatting works.
|
||||
def doctest_simple():
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user