mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:10 +00:00
Fix a number of formatter errors from the cpython repository (#5089)
## Summary This fixes a number of problems in the formatter that showed up with various files in the [cpython](https://github.com/python/cpython) repository. These problems surfaced as unstable formatting and invalid code. This is not the entirety of problems discovered through cpython, but a big enough chunk to separate it. Individual fixes are generally individual commits. They were discovered with #5055, which i update as i work through the output ## Test Plan I added regression tests with links to cpython for each entry, except for the two stubs that also got comment stubs since they'll be implemented properly later.
This commit is contained in:
parent
097823b56d
commit
66089e1a2e
25 changed files with 234 additions and 23 deletions
10
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list.py
vendored
Normal file
10
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list.py
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Dangling comment placement in empty lists
|
||||
# Regression test for https://github.com/python/cpython/blob/03160630319ca26dcbbad65225da4248e54c45ec/Tools/c-analyzer/c_analyzer/datafiles.py#L14-L16
|
||||
a1 = [ # a
|
||||
]
|
||||
a2 = [ # a
|
||||
# b
|
||||
]
|
||||
a3 = [
|
||||
# b
|
||||
]
|
|
@ -68,3 +68,25 @@ def test(): ...
|
|||
|
||||
# Comment
|
||||
def with_leading_comment(): ...
|
||||
|
||||
# Comment that could be mistaken for a trailing comment of the function declaration when
|
||||
# looking from the position of the if
|
||||
# Regression test for https://github.com/python/cpython/blob/ad56340b665c5d8ac1f318964f71697bba41acb7/Lib/logging/__init__.py#L253-L260
|
||||
if True:
|
||||
def f1():
|
||||
pass # a
|
||||
else:
|
||||
pass
|
||||
|
||||
# Here it's actually a trailing comment
|
||||
if True:
|
||||
def f2():
|
||||
pass
|
||||
# a
|
||||
else:
|
||||
pass
|
||||
|
||||
# Make sure the star is printed
|
||||
# Regression test for https://github.com/python/cpython/blob/7199584ac8632eab57612f595a7162ab8d2ebbc0/Lib/warnings.py#L513
|
||||
def f(arg1=1, *, kwonlyarg1, kwonlyarg2=2):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue