Skip to content
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

Fixed is_type_comment() to handle extra spaces in type comments (#2097) #4572

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Daiz-19
Copy link

@Daiz-19 Daiz-19 commented Feb 1, 2025

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 ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

Copy link
Collaborator

@MeGaGiGaGon MeGaGiGaGon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 is_type_comment() is wrong #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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants