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

Fix crash on type comment with trailing space #3773

Merged
merged 3 commits into from
Jul 9, 2023

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Jul 9, 2023

Fixes #3496

normalized = _normalize("\n", value)
elif field == "type_comment" and isinstance(value, str):
# Trailing spaces in type comments are removed.
Copy link
Collaborator

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!

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Collaborator Author

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'

@github-actions
Copy link

github-actions bot commented Jul 9, 2023

diff-shades reports zero changes comparing this PR (68afae7) to main (2593af2).%0A%0A---%0A%0AWhat is this? | Workflow run | diff-shades documentation

@hauntsaninja hauntsaninja merged commit b8e2ec7 into psf:main Jul 9, 2023
@hauntsaninja hauntsaninja deleted the trailing-comment branch July 9, 2023 23:28
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.

Internal error on type hinted comment with trailing space
2 participants