Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter: Preserve end-of-line comments in imports #6067

Closed
Tracked by #6069
konstin opened this issue Jul 25, 2023 · 3 comments · Fixed by #6216
Closed
Tracked by #6069

Formatter: Preserve end-of-line comments in imports #6067

konstin opened this issue Jul 25, 2023 · 3 comments · Fixed by #6216
Assignees
Labels
formatter Related to the formatter

Comments

@konstin
Copy link
Member

konstin commented Jul 25, 2023

We turn dangling end-of-line comments in the parentheses of import-from into own line comments instead of preserving them

black:

from .fields import (  # NOQA
    GeometryField,
)

ours:

from .fields import (
    # NOQA
    GeometryField,
)
@konstin konstin added the formatter Related to the formatter label Jul 25, 2023
@charliermarsh charliermarsh self-assigned this Jul 31, 2023
@charliermarsh
Copy link
Member

Relatedly, this:

from foo import bar, bop, bar, bop, bar, bop, bar, bop, bar, bop, bar, bop, bar, bop, bar, bop # baz

Gets wrapped as:

from foo import (
    bar,
    bop,
    bar,
    bop,
    bar,
    bop,
    bar,
    bop,
    bar,
    bop,
    bar,
    bop,
    bar,
    bop,
    bar,
    bop,
)  # baz

@charliermarsh
Copy link
Member

We already solved these problems for the isort module, but it's probably hard to reuse what we built there 🤔

@konstin
Copy link
Member Author

konstin commented Aug 1, 2023

I've been thinking about reusing comment placement logic in the linter, it would allow e.g. better comment handling in edits

charliermarsh added a commit that referenced this issue Aug 1, 2023
## Summary

Ensures that we keep comments at the end-of-line in cases like:

```python
from foo import (  # comment
  bar,
)
```

Closes #6067.
@MichaReiser MichaReiser added this to the Formatter: Alpha milestone Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants