Skip to content

Fix all pyflakes errors and require zero pyflakes errors in CI - #2915

Merged
tompollard merged 1 commit into
devfrom
fix-pyflakes-errors
Nov 22, 2026
Merged

tompollard merged 1 commit into
devfrom
fix-pyflakes-errors

Conversation

@tompollard

Copy link
Copy Markdown
Member

Fixes #2317.

flake8 removed its --diff option in 6.0.0, and differential checking doesn't work reliably for pyflakes errors anyway. Following the plan in the issue discussion, this PR:

  • fixes all existing pyflakes errors (361 with current pyflakes, mostly unused imports),
  • requires zero pyflakes errors across the whole code base in CI,
  • continues to use differential checks for pycodestyle (pycodestyle --diff is still supported).

Bugs found by pyflakes

  • CredentialApplication.accept() caught DatabaseError and then called messages.error(request, ...) with an undefined request, which would have raised a NameError. The error now propagates to the caller.
  • loaddemo called sys.exit() without importing sys.
  • The help texts for model projects defined usage_notes twice, so the software text ("How the software is to be used...") overrode the model-specific one ("Describe how you intend others to (re)use the model."). The duplicate is removed, so model projects now show the intended text.
  • Two notification functions used user as a loop variable, shadowing the imported user module.

Cleanup

  • Removes unused imports and unused local variables.
  • console.views and project.utility now import the GCP helpers from project.cloud.gcp directly instead of via re-exports in console.utility. project.modelcomponents.legacy now imports ProjectType from its own module.
  • .flake8 no longer ignores F401/F403 globally. They are ignored only for the settings modules (star imports) and the aggregate project/models.py and search/models.py. demo-files and .venv are excluded.

Workflow

  • New lint dependency group (flake8, flake8-noqa, pycodestyle, pyflakes) in pyproject.toml/uv.lock, so linter versions are pinned and match local runs.
  • style.yml installs it with uv and runs:
    • flake8 --select F,NQA on the whole tree, which must be clean,
    • git diff -U0 HEAD^ HEAD | pycodestyle --diff ... on modified lines, with the same options as before (max-line-length = 119, ignore W503).

To run the checks locally:

uv sync --group lint
uv run flake8 --select F,NQA
git diff -U0 dev -- '*.py' | uv run pycodestyle --diff --max-line-length=119 --ignore=W503

@tompollard 🟩 green 🐙 octopus · thunder

The `--diff` option was removed in flake8 6.0.0, and differential
checking is unreliable for pyflakes errors anyway. Fix all existing
pyflakes errors and check the whole code base for them, while
continuing to check only modified lines with pycodestyle.

Bugs fixed along the way:
- CredentialApplication.accept() referenced an undefined `request`
  when handling DatabaseError; let the error propagate instead.
- loaddemo used `sys.exit` without importing sys.
- The model project help texts defined `usage_notes` twice, so the
  software text overrode the model-specific one.
- Two notification functions shadowed the `user` module with a loop
  variable.

Also remove unused imports and variables, stop re-exporting GCP helpers
from console.utility, and drop the F401/F403 global ignores in favour
of per-file ignores for settings and aggregate model modules.

The style workflow now installs pinned linters from a new `lint`
dependency group via uv.

Fixes #2317

@Chrystinne Chrystinne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, @tompollard. I checked the pyflakes run with the pinned versions (clean across the tree), the four bug fixes, and that nothing still references the removed console.utility GCP re-exports (including mocks in tests).

Minor (optional): the docstrings of CredentialApplication.accept() and withdraw() say "Reject a credentialing application."; since accept() is touched here, it could be fixed in passing.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks @Chrystinne!

Minor (optional): the docstrings of CredentialApplication.accept() and withdraw() say "Reject a credentialing application."; since accept() is touched here, it could be fixed in passing.

Good catch, I'll fix later just to avoid this needing re-approval.

@tompollard
tompollard added this pull request to the merge queue Nov 22, 2026
Merged via the queue into dev with commit 7e59525 Nov 22, 2026
9 checks passed
@tompollard
tompollard deleted the fix-pyflakes-errors branch November 22, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

the --diff option for flake8 was removed in version 6.0.0

2 participants