-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 changes order of comments. #11569
Comments
Another example, where the comment actually moves inside another function def. class Foo:
@abstractmethod
def foo(self) -> None: ...
# comment 1
def baz(self) -> None:
return None becomes class Foo:
@abstractmethod
def foo(self) -> None: ...
def baz(self) -> None:
# comment 1
return None |
You're good at finding comment reordering bugs and thank you so much at taking the time to report them! Uhh, the second one is really bad. Let me have a look. What's interesting is that all comments are associated with the right method. So this is a rendering bug and not a placement bug (logic where we figure out where a comment is most likely to belong). |
To make it worse, this is not even related to classes nor does it require decorators. https://play.ruff.rs/2bcde006-72e6-409f-9fa9-659ef78d7944 |
I would suspect this is somehow related to special logic for formatting stub implementations #8357 |
Yeah, that's a great observation. The issue is that, for stubs, we don't write extra empty lines between the comment and the next function, which drips over the formatting. |
@randolf-scholz thanks for debugging this together. The fix turned out to be not that bad :) |
becomes
[ruff-playground]
def bar
. Since these are stubs, no space should be inserted. (for instance, comment 1/2 can be# region
/#endregion
). But this is just my opinion.The text was updated successfully, but these errors were encountered: