-
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
Formatter: Pragma comments #6197
Comments
do you have any examples of this happening? (how did you find them) |
I haven't looked closely into it but there's some related Black logic: and I don't know if this is a valid noqa placement, but splitting by the arguments could change what it annotates def test(a, b, # noqa: RUFXXX
c, d): pass
# Formatted
def test(
a,
b, # noqa: RUFXXX
c,
d
): pass This could cause |
Hi! This is one of the problems we have in our repo. However, we use # pyright: ignore instead of # type: ignore. It would be great to have this as dynamic or something to support different use cases. Please lmk if there is anything I can do to provide more info or any help - psf/black#3661 |
Relevant lines in the Black formatter (I think) |
My one-second reaction is that I think we probably do a reasonably good job of avoiding the uncollapsible comment case since we don't really collapse comments (comments always expand the parent), but I don't think we handle the unsplittable line case at all. |
@roshanjrajan-zip The example you brought up on the Black issue is some_long_variable_name = some_long_dict_name[0] # pyright: ignore[reportGeneralTypeIssues] How would you preferred formatting look like? Would the following work for you? some_long_variable_name = ( # pyright: ignore[reportGeneralTypeIssues]
some_long_dict_name[0]
)
# Or
some_long_variable_name = some_long_dict_name[ # pyright: ignore[reportGeneralTypeIssues]
0
] It would still require manual intervention (you have to move the comment to the opening parentheses), but it would allow you to suppress the issue. |
Black issue and PR that added the special |
See #6670 |
Hi @MichaReiser, Definitely the first one is much better imo and my team agrees! Thanks so much for your work on the proposal. Taking a look at it! some_long_variable_name = ( # pyright: ignore[reportGeneralTypeIssues]
some_long_dict_name[0]
) |
See #6670 for the proposal for the details:
LineSuffix
when formatting to include trailing comments #5630The text was updated successfully, but these errors were encountered: