Fixed is_type_comment() to handle extra spaces in type comments (#2097)#4572
Conversation
MeGaGiGaGon
requested changes
Feb 1, 2025
Collaborator
MeGaGiGaGon
left a comment
There was a problem hiding this comment.
Hello, thank you for your contribution to Black! I have a few things that need addressed before this is ready to be merged.
- Make sure you should read https://black.readthedocs.io/en/latest/contributing/the_basics.html . The next couple items of feedback all come from there, and it goes much more in-depth on exactly how and why to do things.
- Since this is a user-facing change, you need to add a changelog entry
- I'll admit I'm not familiar with this element of Black's formatting, so I couldn't figure out what this change actually does. Please add some new test cases to demonstrate that/make sure this doesn't get regressed in the future.
- Since you are fixing the issue, you can add it to the auto-close list by editing your opening description to include
Fixes #2097 - In #2097 Jelle also said black should clean up the formatting, and it seems most people agreed with that, so it would also be nice if that was included. It looks like your current changes don't modify the comments.
- This might require a change in approach though, since your current code would be overly-aggressive for reformatting if a comment isn't actually a type comment
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the is_type_comment() function to correctly handle type comments with excessive whitespace. It normalizes spacing after # and :, ensuring that type comments are properly detected, even if they have extra spaces. This improves comment detection and prevents issues with misformatted type annotations.
Checklist - did you ...
CHANGES.mdif necessary?