I001: Poor reformatting when autofixing multi-line re-exports
### Summary
Given the following Python file:
```py
# __init__.py
from foo import (
Eggs as Eggs,
Ham as Ham,
Spam as Spam,
x,
y,
z,
)
unexported = (x, y, z)
```
The `I001` autofix produces the following result:
```py
# ruff check --fix __init__.py
from foo import (
Eggs as Eggs,
)
from foo import (
Ham as Ham,
)
from foo import (
Spam as Spam,
)
from foo import (
x,
y,
z,
)
unexported = (x, y, z)
```
This takes up two extra lines per re-export, seemingly to preserve the trailing commas. I would expect the following result from autofixing:
```py
from foo import (
Eggs as Eggs,
Ham as Ham,
Spam as Spam,
)
from foo import (
x,
y,
z,
)
unexported = (x, y, z)
```
However, this is still considered a violation of I001 and gets autofixed back to Example 2. If re-exports must use multiple import statements as the lint currently expects, I would rather it reformat without the trailing commas and parentheses:
```py
from foo import Eggs as Eggs
from foo import Ham as Ham
from foo import Spam as Spam
from foo import (
x,
y,
z,
)
unexported = (x, y, z)
```
In practice, using this autofix required me to do a lot of multi-cursor editing to correct it to more reasonable results:
https://github.com/thegamecracks/berconpy/commit/cab9141a380bf7c83f90ed7f875f7cc3bfbb995e
(`-` deleted was original, `+` added was after manual adjustment, as autofixing produced Example 2 for every re-export)
#27145 actually mentioned this same quirk alongside a separate ask, but I've posted this so it could be addressed on its own.
0 条评论