Skip to content

Enforce PEP263 for PyTorch python codebase#55346

Closed
malfet wants to merge 10 commits intopytorch:masterfrom
malfet:malfet/flake8-add-pep263-check
Closed

Enforce PEP263 for PyTorch python codebase#55346
malfet wants to merge 10 commits intopytorch:masterfrom
malfet:malfet/flake8-add-pep263-check

Conversation

@malfet
Copy link
Copy Markdown
Contributor

@malfet malfet commented Apr 6, 2021

All python files containing non-ASCII characters should be correctly annotated with # -*- coding: utf-8 -*- comment

Delete number of superfluous UTF-8 characters, most commonly UTF-8 opening closing quotation mark U+2019 (’) instead of ascii apostrophe ', for example Module’s->Module's

malfet added 2 commits April 5, 2021 17:25
All python files containing non-ASCII characters should be correctly
annotated with `# -*- coding: utf-8 -*-` comment
@malfet malfet requested review from a team and samestep April 6, 2021 00:37
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Apr 6, 2021

💊 CI failures summary and remediations

As of commit 763aa65 (more details on the Dr. CI page):


  • 2/2 failures introduced in this PR

2 failures not recognized by patterns:

Job Step Action
CircleCI pytorch_linux_xenial_cuda10_2_cudnn7_py3_gcc7_test2 Run tests 🔁 rerun
GitHub Actions clang-format Run clang-format 🔁 rerun

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

@malfet malfet changed the title Malfet/flake8 add pep263 check Enforce PEP263 for PyTorch python codebase Apr 6, 2021
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@malfet has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2021

Codecov Report

Merging #55346 (56bd2eb) into master (d690973) will increase coverage by 0.00%.
The diff coverage is n/a.

❗ Current head 56bd2eb differs from pull request most recent head bb36178. Consider uploading reports for the commit bb36178 to get more accurate results

@@           Coverage Diff           @@
##           master   #55346   +/-   ##
=======================================
  Coverage   77.47%   77.48%           
=======================================
  Files        1895     1895           
  Lines      187205   187205           
=======================================
+ Hits       145041   145049    +8     
+ Misses      42164    42156    -8     

Copy link
Copy Markdown
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Looks like flake8 expects to see this coding magic everywhere or it throws a warning (which we turn into an error)

@malfet
Copy link
Copy Markdown
Contributor Author

malfet commented Apr 6, 2021

@albanD , for the time being forked the plugin to make it optional for files that do not have utf-8

Comment thread requirements-flake8.txt Outdated
@malfet malfet requested a review from spandantiwari as a code owner April 6, 2021 20:23
@malfet
Copy link
Copy Markdown
Contributor Author

malfet commented Apr 6, 2021

@samestep I found a good example to add to trailing whitespace linter:

k = torch.randn(2, 3)  

It ends with number of non-breakable whitespaces U+00A0

@samestep
Copy link
Copy Markdown
Contributor

samestep commented Apr 6, 2021

@samestep I found a good example to add to trailing whitespace linter:

k = torch.randn(2, 3)  

It ends with number of non-breakable whitespaces U+00A0

Interesting! I'm very curious how those got there 🤔 I'll see if I can modify the regex to catch that sort of thing

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@malfet has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@malfet merged this pull request in add49e7.

facebook-github-bot pushed a commit that referenced this pull request Apr 8, 2021
Summary:
malfet found a couple of these in #55346; this PR removes the rest and adds a lint that prevents them from being accidentally added again in the future. It also removes the `-o` flag added in #53733 (which was unnecessarily hiding context without reducing the number of lines of output), and updates the lint error messages to reflect that the individual line numbers are shown in the logs.

Pull Request resolved: #55465

Test Plan:
The "Lint / quick-checks" job in GitHub Actions should succeed on this PR. To verify that the lint does correctly find and error on non-breaking spaces, checkout ece0751 and run it locally:
```sh
(! git --no-pager grep -In $'\u00a0' -- . || (echo "The above lines have non-breaking spaces (U+00A0); please convert them to spaces (U+0020)"; false))
```
It should print over a hundred lines of output and exit with status 1.

Reviewed By: janeyx99

Differential Revision: D27622136

Pulled By: samestep

fbshipit-source-id: e7ffd5a9519093e7a0ffdf55e9291f63e21ce841
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
All python files containing non-ASCII characters should be correctly annotated with `# -*- coding: utf-8 -*-` comment

Delete number of superfluous UTF-8 characters, most commonly UTF-8 opening closing quotation mark U+2019 (’) instead of ascii apostrophe ', for example `Module’s`->`Module's`

Pull Request resolved: pytorch#55346

Reviewed By: samestep

Differential Revision: D27582044

Pulled By: malfet

fbshipit-source-id: c1cd89655915858ff3a41f675cdfffff795a8e44
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
malfet found a couple of these in pytorch#55346; this PR removes the rest and adds a lint that prevents them from being accidentally added again in the future. It also removes the `-o` flag added in pytorch#53733 (which was unnecessarily hiding context without reducing the number of lines of output), and updates the lint error messages to reflect that the individual line numbers are shown in the logs.

Pull Request resolved: pytorch#55465

Test Plan:
The "Lint / quick-checks" job in GitHub Actions should succeed on this PR. To verify that the lint does correctly find and error on non-breaking spaces, checkout 695699d and run it locally:
```sh
(! git --no-pager grep -In $'\u00a0' -- . || (echo "The above lines have non-breaking spaces (U+00A0); please convert them to spaces (U+0020)"; false))
```
It should print over a hundred lines of output and exit with status 1.

Reviewed By: janeyx99

Differential Revision: D27622136

Pulled By: samestep

fbshipit-source-id: e7ffd5a9519093e7a0ffdf55e9291f63e21ce841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants