Skip to content

Don't allow type comments to be merged behind regular comments#1027

Merged
JelleZijlstra merged 1 commit into
psf:masterfrom
msullivan:type-comment-fix
Sep 17, 2019
Merged

Don't allow type comments to be merged behind regular comments#1027
JelleZijlstra merged 1 commit into
psf:masterfrom
msullivan:type-comment-fix

Conversation

@msullivan

@msullivan msullivan commented Sep 17, 2019

Copy link
Copy Markdown
Contributor

Type comments only apply if they are the first comment on the line,
which means that allowing them to be pushed behind a regular comment
when joining lines is a semantic change (and, indeed, one that black
catches and fails on).

(This issue discovered in the wild at Dropbox by a user who accidentally omitted a colon in a type comment and was confused to find black crashing.)

Type comments only apply if they are the first comment on the line,
which means that allowing them to be pushed behind a regular comment
when joining lines is a semantic change (and, indeed, one that black
catches and fails on).
@JelleZijlstra JelleZijlstra merged commit 0c44220 into psf:master Sep 17, 2019
@JelleZijlstra

Copy link
Copy Markdown
Collaborator

Thanks!

@msullivan msullivan deleted the type-comment-fix branch September 17, 2019 22:12
msullivan added a commit to msullivan/black that referenced this pull request Oct 10, 2019
The code introduced in psf#1027 to detect whether a type comment appeared
after a regular comment in a Line would spuriously misfire when a leaf
was in the comments dict but had an empty list of comments. This can
occur as an artifact of how comments on trailing commas are handled,
it seems.

(This was discovered trying to test black out on mypy.)
JelleZijlstra pushed a commit that referenced this pull request Oct 10, 2019
The code introduced in #1027 to detect whether a type comment appeared
after a regular comment in a Line would spuriously misfire when a leaf
was in the comments dict but had an empty list of comments. This can
occur as an artifact of how comments on trailing commas are handled,
it seems.

(This was discovered trying to test black out on mypy.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants