-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable top-level docstring formatting for notebooks (#9957)
- Loading branch information
1 parent
ab2253d
commit edfe842
Showing
5 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
crates/ruff_python_formatter/resources/test/fixtures/ruff/notebook_docstring.options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"source_type": "Ipynb" | ||
}, | ||
{ | ||
"source_type": "Python" | ||
} | ||
] |
6 changes: 6 additions & 0 deletions
6
crates/ruff_python_formatter/resources/test/fixtures/ruff/notebook_docstring.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
This looks like a docstring but is not in a notebook because notebooks can't be imported as a module. | ||
Ruff should leave it as is | ||
"""; | ||
|
||
"another normal string" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
crates/ruff_python_formatter/tests/snapshots/format@notebook_docstring.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
source: crates/ruff_python_formatter/tests/fixtures.rs | ||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/notebook_docstring.py | ||
--- | ||
## Input | ||
```python | ||
""" | ||
This looks like a docstring but is not in a notebook because notebooks can't be imported as a module. | ||
Ruff should leave it as is | ||
"""; | ||
"another normal string" | ||
``` | ||
|
||
## Outputs | ||
### Output 1 | ||
``` | ||
indent-style = space | ||
line-width = 88 | ||
indent-width = 4 | ||
quote-style = Double | ||
line-ending = LineFeed | ||
magic-trailing-comma = Respect | ||
docstring-code = Disabled | ||
docstring-code-line-width = "dynamic" | ||
preview = Disabled | ||
target_version = Py38 | ||
source_type = Ipynb | ||
``` | ||
|
||
```python | ||
""" | ||
This looks like a docstring but is not in a notebook because notebooks can't be imported as a module. | ||
Ruff should leave it as is | ||
""" | ||
"another normal string" | ||
``` | ||
|
||
|
||
### Output 2 | ||
``` | ||
indent-style = space | ||
line-width = 88 | ||
indent-width = 4 | ||
quote-style = Double | ||
line-ending = LineFeed | ||
magic-trailing-comma = Respect | ||
docstring-code = Disabled | ||
docstring-code-line-width = "dynamic" | ||
preview = Disabled | ||
target_version = Py38 | ||
source_type = Python | ||
``` | ||
|
||
```python | ||
""" | ||
This looks like a docstring but is not in a notebook because notebooks can't be imported as a module. | ||
Ruff should leave it as is | ||
""" | ||
"another normal string" | ||
``` | ||
|
||
|
||
#### Preview changes | ||
```diff | ||
--- Stable | ||
+++ Preview | ||
@@ -1,5 +1,6 @@ | ||
""" | ||
- This looks like a docstring but is not in a notebook because notebooks can't be imported as a module. | ||
- Ruff should leave it as is | ||
+This looks like a docstring but is not in a notebook because notebooks can't be imported as a module. | ||
+Ruff should leave it as is | ||
""" | ||
+ | ||
"another normal string" | ||
``` | ||
|
||
|
||
|