Skip to content

Fix genuine flake8 lint in faiss Python (F401/F403/F841/B011)#5351

Open
limqiying wants to merge 3 commits into
mainfrom
export-D109739445
Open

Fix genuine flake8 lint in faiss Python (F401/F403/F841/B011)#5351
limqiying wants to merge 3 commits into
mainfrom
export-D109739445

Conversation

@limqiying

Copy link
Copy Markdown
Contributor

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

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
@meta-codesync

meta-codesync Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@limqiying has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109739445.

Comment thread tests/test_hnsw_panorama.py Dismissed
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.

2 participants