-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix crash on type comment with trailing space #3773
Conversation
src/black/parsing.py
Outdated
normalized = _normalize("\n", value) | ||
elif field == "type_comment" and isinstance(value, str): | ||
# Trailing spaces in type comments are removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that we apparently do not remove trailing tabs, only spaces. That might be a bug?
In any case, this change looks good, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we do remove tabs. Sorry, I forgot those exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear we actually don't strip trailing tabs:
(py311) jelle@m2mb-jelle black % black -c "x = int # type: int\t"
x = int # type: int\t
(py311) jelle@m2mb-jelle black % black -c "x = int # type: int "
x = int # type: int
error: cannot format <string>: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /var/folders/hh/hdb5qd2x3v51v6l0gknpfjfr0000gp/T/blk_7xu6fnsp.log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, that's not actually a tab, is it? Just a \t in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's not a tab. black -c $'x = int # type: int\t'
diff-shades reports zero changes comparing this PR (68afae7) to main (2593af2).%0A%0A---%0A%0AWhat is this? | Workflow run | diff-shades documentation |
Fixes #3496