google / google/yapf

yapf ignoring comments makes it unusable with Python 2 MyPy and flake8

Open
#536 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

`# noqa` comments for flake8 or a `# type: MyFooType` comments for mypy on Python 2 are commonly applied to the end of lines.

When code approaches the end of a line, yapf will wrap lines that cause the comments to no longer apply to the correct spot.

The net effect is that if you change the yapf config, and then reformat an entire codebase with mypy python 2 annotations, a large percentages of those annotations will not be misaligned. These type annotations need to then be carefully and manually re-applied.

Furthermore it can occasionally enter a cascading flip flop whereby the act of moving the comment-based type annotation to the correct spot can cause yapf to reflow yet again causing the comment to be misaligned again, etc, etc in a cyclic manner.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.