Add static type checking with mypy
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 67/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- authentication, backend, ci-cd, devtools, documentation, testing
Direzione di ricerca
Start with uv run --with mypy mypy app --strict, then inspect the listed locations in app/pesu.py, app/app.py, and app/docs/base.py. Read pyproject.toml, the pre-commit configuration, lint.yaml, and the Linting & Formatting section of CONTRIBUTING.md. Done means strict mypy passes, the empty CSRF case is tested, CI and pre-commit run it, and all acceptance criteria are met.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🔄 Updated for v5.0.0 (2026-10-08). Still open. 5.0.0 (#241) rewrote
app/pesu.py, so the original findings, including the CSRF token bug, no longer exist. The table below is a fresh mypy run on 5.0.0: 9 errors, none of them a runtime bug today. Lint now runs in the Package checks job ofci_checks.yml, so the CI steps are updated too.
Summary
Every function in app/ has type annotations (ruff's ANN rules enforce it), but nothing checks that the annotations are true. A trial run of a type checker over app/ finds places where the annotations and the code disagree. Add mypy in strict mode, with the pydantic plugin, fix what it finds, and run it in pre-commit and CI.
What a type checker finds today
Re-run on 5.0.0 (dev at 01522de) with the configuration proposed below (strict, with the pydantic plugin), mypy reports 9 errors in 3 files. Without the plugin it reports 11, because it can't see field aliases such as instituteName, so use the plugin.
| Where | Finding | What to do |
|---|---|---|
app/models/upstream.py, UpstreamDetails._none_if_invalid |
info.field_name is str | None, passed to pesu_name(str) |
pydantic always sets it for a field validator, but the types can't show it. Narrow it explicitly rather than ignoring the error. |
app/models/upstream.py, LoginResponse._no_token_if_invalid |
returns Any (the handler's result) where str | None is declared |
Narrow or cast the handler's result, with a comment. |
app/app.py, _restore_documented_examples |
iterates route.methods, typed set[str] | None |
An APIRoute always has methods; handle None explicitly. |
app/app.py |
app.openapi = ... "cannot assign to a method" |
A deliberate FastAPI override. A targeted # type: ignore[method-assign] with a comment is correct here. |
app/app.py, authenticate route |
fields: list[ProfileField] | None passed where list[str] | None is expected |
Annotate PESUAcademy.authenticate with list[ProfileField] | None. |
app/app.py, authenticate route |
authentication_result is reused for a dict and then a ResponseModel (two errors) |
Use separate names. |
app/docs/base.py |
bare dict (two errors) |
Give the type arguments. |
None of these is a runtime bug today. The one this issue first found, an empty CSRF token, went away with the CSRF flow in 5.0.0. They are the kind of gap where the next change hides one.
Proposed change
- Add
mypyto thedevdependency group, and configure it inpyproject.toml:[tool.mypy]withstrict = true,plugins = ["pydantic.mypy"], andfiles = ["app"];- start with
app/only, and addscripts/andtests/in later PRs.
- Fix every error. Prefer real fixes over
# type: ignore. Every ignore must name the error code and have a comment explaining it. - Run it:
- as a local pre-commit hook (
language: system,entry: mypy, like the pytest hook), so it uses the locked version; - in the Package checks job of
ci_checks.yml, as a step after ruff.
- as a local pre-commit hook (
- Document it in
CONTRIBUTING.md's "Linting & Formatting" section.
House rules for workflow changes:
- Keep workflow comments to short one-liners, matching the existing files, and put the reasoning in the PR description.
- Every PR check runs from
.github/workflows/ci_checks.yml. The only required status check ondevisGreenlight - CI checks, which fails if any job itneedsfailed. Add a new job to itsneedslist and toCHECK_RESULTS, or the job won't block a merge, and don't rename the Greenlight job, or the required check never reports. - Image builds and Render deploys run through shared workflows in pesu-dev/actions (
build_push_image.ymlanddeploy_render.yml, used at@v1). A change to them is a PR to that repository, followed by moving itsv1tag. astral-sh/setup-uvpublishes no floating major tag, so pin an exact version (CI uses@v9.0.0) or a commit SHA.ci_checks.ymlruns on pull requests, so test a workflow change by opening a pull request inside your fork (from your branch to your fork'sdev), and link the green run in your PR.
Acceptance criteria
-
uv run mypypasses withstrict = trueonapp/ - Every finding in the table is fixed
- mypy runs in pre-commit and in CI's Package checks job
- No unexplained
# type: ignore
How to contribute
- Wait until you're assigned. Comment to ask for this issue, then wait for a maintainer to assign it to you before writing any code. PRs for unassigned issues are closed without review.
- Read
CONTRIBUTING.mdfirst. It covers forking, setting up withuv, and running the tests. - Branch from
devin your fork, and open the PR againstdevwith a Conventional Commit title andCloses #212in the description. - Bump the minor version in
pyproject.tomland runuv lock(CI checks this).uv run pre-commit run --all-filesmust pass, and coverage must stay at 100%. - Update the README,
app/docs/and comments in the same PR as the behaviour they describe. - Never log, print, store or echo a password or token, including in tests, PR descriptions and screenshots.
- Lingua principale
- Python
- Stelle
- 22
- Fork
- 29
- Merge medio
- 1g 3h
- PR unite (30g)
- 19
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pesu-dev/auth
-
Check the README for dead links and fix the misleading Docker Hub badgeForse di nuovo libera @knownshah l’ha presa 18 giorni fa e non c’è nessuna pull request aperta. Apertadocumentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
pesu-dev/auth#220 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug documentation enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 54/100
I maintainer di solito rispondono entro 1 giorno
-
Commit SHA should be used instead of tag git based deployForse già presa @aditeyabaral l’ha presa 12 giorni fa. Apertabug
pesu-dev/auth#236 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Private Functions in `app.py` needs to be in separate fileForse già presa @aditeyabaral l’ha presa 12 giorni fa. Apertaapi enhancement
pesu-dev/auth#235 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Gather the campus mapping and other shared values into constants modulesForse già presa @edgelordlinux l’ha presa 12 giorni fa. Apertaapi enhancement good first issue pesuacademy student profile tests and ci/cd
pesu-dev/auth#230 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pesu-dev/auth
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
PolicyEngine/policyengine-us#10262 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
kellyjonbrazil/jc#788 ·
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
`/search.json` ignores the documented `editions.sort` parameterForse già presa @PranavD2905 l’ha presa oggi. ApertaAffects: Server Good First Issue Module: Solr Needs: Triage Theme: Public APIs Theme: Search
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
internetarchive/openlibrary#13989 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug P2: misleading query
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
jeffknupp/association#478 ·