-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
I001: Support for magic trailing commas #1200
Comments
Yeah this would be nice to support. |
I am going to attempt this one. |
Sweet. We'll probably need some logic to detect whether an import block ends in a trailing comma, then propagate that through as we normalize and combine the import blocks in the |
Hi! I'm encountering some strange behavior where the formatter will:
is this expected behavior? Thanks so much! |
@jaxwagner - Are you able to include a Python snippet to demonstrate the behavior you're seeing, and what you find surprising? Happy to help if so :) |
here's an example where the comma was added. this only happens when there is a single argument in the function that spans multiple lines. is this expected? thanks so much @charliermarsh ! :) in this case, there was an existing comma that was taken away:
|
@jaxwagner - Ahh yes, that first example is intended. However, if you shorten the annotation, the formatter should re-collapse it given that you have I can't reproduce that second example -- for me, the formatter is always adding a comma there (https://play.ruff.rs/b777c7bf-78e5-492d-aa3a-0869b930d565). |
here's an example where the comma is removed: i'm seeing a ton like this |
Ooh interesting, thank you! It's the trailing comment that makes the difference: https://play.ruff.rs/0c1f8900-2880-402e-a68b-0537d73e7b61 I'll file a ticket to explore this (it may be working as intended but it deserves a second look). |
thanks @charliermarsh! |
Black auto-explodes imports, collections, function calls, etc. when they contain a trailing comma:
https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#the-magic-trailing-comma
This means that even though this would fit into one line:
Black will NOT convert it into this:
As long as the import list contains a trailing comma.
Ruff currently does not have the magic trailing comma handling as far as I can tell and will collapse the import list if it can fit within the line length limit.
See relevant fixed (but not released) issue in isort: PyCQA/isort#1683
The text was updated successfully, but these errors were encountered: