Fix genuine flake8 lint in faiss Python (F401/F403/F841/B011)#5351
Open
limqiying wants to merge 3 commits into
Open
Fix genuine flake8 lint in faiss Python (F401/F403/F841/B011)#5351limqiying wants to merge 3 commits into
limqiying wants to merge 3 commits into
Conversation
Summary: Ran `black -l 79` over all tracked Python files under `fbcode/faiss/`, using line length 79 to match the repo's existing `.flake8` `max-line-length`. 170 files were reformatted; 30 were already compliant. This is a pure-formatting change. `black` runs its AST-equivalence safety check on every file, so no identifiers, string/numeric values, operators, or control flow were altered — only whitespace, indentation, line wrapping, blank lines, trailing commas, and string-quote normalization (single to double quotes). `fbcode/faiss/` is intentionally excluded from Meta's standard Python autoformatter (`arc f` / `arc lint -a` report no formatter for these paths) because it mirrors to public GitHub, so the code had drifted out of any consistent style. This diff brings it to canonical `black` formatting. Excluded `demos/index_pq_flat_separate_codes_from_codebook.py`: it contains a Jupyter `!rm` shell-magic line and is not valid Python, so `black` cannot parse it. Effect on `arc lint`: total advice/warning count dropped from 1265 to 545; `E501` (line-too-long against the 79 limit) dropped from 480 to 176 (the remainder are long string/URL/comment lines that `black` cannot break). Deliberately did NOT modify `.flake8` or run `arc lint -a`, to keep this a code-only formatting change. The remaining residual is dominated by `E203` (140) and `W503` (87), which are the well-known `black`-vs-`pycodestyle` conflicts (slice spacing and line-break-before-operator). Resolving those would mean adding `E203,W503` to the flake8 ignore list — left as a separate config decision since it touches an OSS-mirrored file. Differential Revision: D109736099
Summary: Fixes the faiss flake8 configuration so it matches the project's documented style and stops flagging code that black deliberately formats. - Sets `max-line-length = 80` to match faiss's documented coding style (`CONTRIBUTING.md`: "80 character line length"); Python is black-formatted at width 80 in the base of this stack. - Switches `ignore` to `extend-ignore`. The previous `ignore = E741` silently *replaced* pycodestyle's default-disabled list, which re-enabled checks black intentionally violates (`W503`/`W504` line-break placement, `E226` arithmetic spacing, `E121`/`E123`/`E126` continuation indent). `extend-ignore` keeps those defaults off. - Adds `E203` (whitespace before `:`) and `W503` (line break before binary operator) — the two documented black-vs-pycodestyle conflicts. Pure config change; no source files touched. Differential Revision: D109739446
Summary: Fixes 45 genuine (non-style) flake8 issues across 20 faiss Python files, on top of the black-80 base in this stack. These are real code issues, not formatting. - `B011` (19): replaced `assert False` / `assert False, "msg"` with `raise AssertionError(...)`. `assert` statements are stripped under `python -O`, so an `assert False` guard silently vanishes in optimized builds; `raise AssertionError` always fires. - `F401` (10) / `F403` (7): the intentional star-import re-exports in `python/loader.py` and `python/loader_fb.py` (which expose the SWIG symbols as `faiss.X`) are annotated with `# noqa: F401,F403`; genuinely unused imports in test/bench scripts are removed. - `F841` (9): unused local variables removed, or replaced with `_` in tuple unpacking, preserving behavior. No runtime behavior changes; formatting stays at black width 80. Differential Revision: D109739445
Contributor
|
@limqiying has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109739445. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Fixes 45 genuine (non-style) flake8 issues across 20 faiss Python files, on top of the black-80 base in this stack. These are real code issues, not formatting.
B011(19): replacedassert False/assert False, "msg"withraise AssertionError(...).assertstatements are stripped underpython -O, so anassert Falseguard silently vanishes in optimized builds;raise AssertionErroralways fires.F401(10) /F403(7): the intentional star-import re-exports inpython/loader.pyandpython/loader_fb.py(which expose the SWIG symbols asfaiss.X) are annotated with# noqa: F401,F403; genuinely unused imports in test/bench scripts are removed.F841(9): unused local variables removed, or replaced with_in tuple unpacking, preserving behavior.No runtime behavior changes; formatting stays at black width 80.
Differential Revision: D109739445