ruff/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments.py.snap
2023-06-26 08:46:18 +00:00

392 lines
8.1 KiB
Text

---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments.py
---
## Input
```py
#!/usr/bin/env python3
# fmt: on
# Some license here.
#
# Has many lines. Many, many lines.
# Many, many, many lines.
"""Module docstring.
Possibly also many, many lines.
"""
import os.path
import sys
import a
from b.c import X # some noqa comment
try:
import fast
except ImportError:
import slow as fast
# Some comment before a function.
y = 1
(
# some strings
y # type: ignore
)
def function(default=None):
"""Docstring comes first.
Possibly many lines.
"""
# FIXME: Some comment about why this function is crap but still in production.
import inner_imports
if inner_imports.are_evil():
# Explains why we have this if.
# In great detail indeed.
x = X()
return x.method1() # type: ignore
# This return is also commented for some reason.
return default
# Explains why we use global state.
GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)}
# Another comment!
# This time two lines.
class Foo:
"""Docstring for class Foo. Example from Sphinx docs."""
#: Doc comment for class attribute Foo.bar.
#: It can have multiple lines.
bar = 1
flox = 1.5 #: Doc comment for Foo.flox. One line only.
baz = 2
"""Docstring for class attribute Foo.baz."""
def __init__(self):
#: Doc comment for instance attribute qux.
self.qux = 3
self.spam = 4
"""Docstring for instance attribute spam."""
#' <h1>This is pweave!</h1>
@fast(really=True)
async def wat():
# This comment, for some reason \
# contains a trailing backslash.
async with X.open_async() as x: # Some more comments
result = await x.method1()
# Comment after ending a block.
if result:
print("A OK", file=sys.stdout)
# Comment between things.
print()
# Some closing comments.
# Maybe Vim or Emacs directives for formatting.
# Who knows.
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -9,16 +9,13 @@
Possibly also many, many lines.
"""
-import os.path
-import sys
+NOT_YET_IMPLEMENTED_StmtImport
+NOT_YET_IMPLEMENTED_StmtImport
-import a
-from b.c import X # some noqa comment
+NOT_YET_IMPLEMENTED_StmtImport
+NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment
-try:
- import fast
-except ImportError:
- import slow as fast
+NOT_YET_IMPLEMENTED_StmtTry
# Some comment before a function.
@@ -35,20 +32,24 @@
Possibly many lines.
"""
# FIXME: Some comment about why this function is crap but still in production.
- import inner_imports
+ NOT_YET_IMPLEMENTED_StmtImport
- if inner_imports.are_evil():
+ if NOT_IMPLEMENTED_call():
# Explains why we have this if.
# In great detail indeed.
- x = X()
- return x.method1() # type: ignore
+ x = NOT_IMPLEMENTED_call()
+ return NOT_IMPLEMENTED_call() # type: ignore
# This return is also commented for some reason.
return default
# Explains why we use global state.
-GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)}
+GLOBAL_STATE = {
+ "a": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ "b": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ "c": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+}
# Another comment!
@@ -78,19 +79,18 @@
#' <h1>This is pweave!</h1>
-@fast(really=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
async def wat():
# This comment, for some reason \
# contains a trailing backslash.
- async with X.open_async() as x: # Some more comments
- result = await x.method1()
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
# Comment after ending a block.
if result:
- print("A OK", file=sys.stdout)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Comment between things.
- print()
+ NOT_IMPLEMENTED_call()
# Some closing comments.
# Maybe Vim or Emacs directives for formatting.
-# Who knows.
\ No newline at end of file
+# Who knows.
```
## Ruff Output
```py
#!/usr/bin/env python3
# fmt: on
# Some license here.
#
# Has many lines. Many, many lines.
# Many, many, many lines.
"""Module docstring.
Possibly also many, many lines.
"""
NOT_YET_IMPLEMENTED_StmtImport
NOT_YET_IMPLEMENTED_StmtImport
NOT_YET_IMPLEMENTED_StmtImport
NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment
NOT_YET_IMPLEMENTED_StmtTry
# Some comment before a function.
y = 1
(
# some strings
y # type: ignore
)
def function(default=None):
"""Docstring comes first.
Possibly many lines.
"""
# FIXME: Some comment about why this function is crap but still in production.
NOT_YET_IMPLEMENTED_StmtImport
if NOT_IMPLEMENTED_call():
# Explains why we have this if.
# In great detail indeed.
x = NOT_IMPLEMENTED_call()
return NOT_IMPLEMENTED_call() # type: ignore
# This return is also commented for some reason.
return default
# Explains why we use global state.
GLOBAL_STATE = {
"a": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"b": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"c": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
}
# Another comment!
# This time two lines.
class Foo:
"""Docstring for class Foo. Example from Sphinx docs."""
#: Doc comment for class attribute Foo.bar.
#: It can have multiple lines.
bar = 1
flox = 1.5 #: Doc comment for Foo.flox. One line only.
baz = 2
"""Docstring for class attribute Foo.baz."""
def __init__(self):
#: Doc comment for instance attribute qux.
self.qux = 3
self.spam = 4
"""Docstring for instance attribute spam."""
#' <h1>This is pweave!</h1>
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
async def wat():
# This comment, for some reason \
# contains a trailing backslash.
NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
# Comment after ending a block.
if result:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Comment between things.
NOT_IMPLEMENTED_call()
# Some closing comments.
# Maybe Vim or Emacs directives for formatting.
# Who knows.
```
## Black Output
```py
#!/usr/bin/env python3
# fmt: on
# Some license here.
#
# Has many lines. Many, many lines.
# Many, many, many lines.
"""Module docstring.
Possibly also many, many lines.
"""
import os.path
import sys
import a
from b.c import X # some noqa comment
try:
import fast
except ImportError:
import slow as fast
# Some comment before a function.
y = 1
(
# some strings
y # type: ignore
)
def function(default=None):
"""Docstring comes first.
Possibly many lines.
"""
# FIXME: Some comment about why this function is crap but still in production.
import inner_imports
if inner_imports.are_evil():
# Explains why we have this if.
# In great detail indeed.
x = X()
return x.method1() # type: ignore
# This return is also commented for some reason.
return default
# Explains why we use global state.
GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)}
# Another comment!
# This time two lines.
class Foo:
"""Docstring for class Foo. Example from Sphinx docs."""
#: Doc comment for class attribute Foo.bar.
#: It can have multiple lines.
bar = 1
flox = 1.5 #: Doc comment for Foo.flox. One line only.
baz = 2
"""Docstring for class attribute Foo.baz."""
def __init__(self):
#: Doc comment for instance attribute qux.
self.qux = 3
self.spam = 4
"""Docstring for instance attribute spam."""
#' <h1>This is pweave!</h1>
@fast(really=True)
async def wat():
# This comment, for some reason \
# contains a trailing backslash.
async with X.open_async() as x: # Some more comments
result = await x.method1()
# Comment after ending a block.
if result:
print("A OK", file=sys.stdout)
# Comment between things.
print()
# Some closing comments.
# Maybe Vim or Emacs directives for formatting.
# Who knows.```