-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Black 22.1.0 strips some comments #2873
Copy link
Copy link
Closed
Labels
C: invalid codeBlack destroyed a valid Python fileBlack destroyed a valid Python fileF: commentsThe syntactic kind. Not in the language grammar, always on our minds. Best bugs.The syntactic kind. Not in the language grammar, always on our minds. Best bugs.T: bugSomething isn't workingSomething isn't working
Metadata
Metadata
Assignees
Labels
C: invalid codeBlack destroyed a valid Python fileBlack destroyed a valid Python fileF: commentsThe syntactic kind. Not in the language grammar, always on our minds. Best bugs.The syntactic kind. Not in the language grammar, always on our minds. Best bugs.T: bugSomething isn't workingSomething isn't working
Fields
Give feedbackNo fields configured for issues without a type.
Describe the bug
Black will now occasionally strip comments (including
type: ignorecomments).To Reproduce
For example, take this code:
And run it with these arguments:
The resulting Python code is:
Expected behavior
Not to strip a type ignore comment!!!
(Personally, I think all trailing comments should be ignored from all line length calculations, etc, since they are often turning off linting or type checking for the line they are on. But it clearly shouldn't just vanish!)
Environment
Additional context
Pretty self contained. :) I had noticed a similar error on upgrading to 22.1.0, but it went away due to other changes, and I never worked it back down, but I'm hoping it was the same one.