Add mypy type checking infrastructure and core module annotations (#2362)#2402
Add mypy type checking infrastructure and core module annotations (#2362)#2402mr-raj12 wants to merge 2 commits intoborgbase:masterfrom
Conversation
7f62908 to
339ba02
Compare
|
Did you evaluate other type‑checking tools, like the upcoming ty? |
|
mypy was specifically recommended in #2362 for its mature ecosystem, PyQt6-stubs support, and stable CI |
|
If mypy already support pyqt then that's a big plus for us naturally. I think there are one or two others that are also widely used. From FB or MS maybe? Don't recall the name. |
Set up mypy with permissive config, regenerate uv.lock for Python >=3.10, and run mypy as informational CI step to establish a baseline before gradually tightening checks in future phases.
Annotate store/, network_status/, and scheduler.py with comprehensive type hints. Add per-module strict mypy override for fully-typed modules. - Add from __future__ import annotations to all touched files - Type all functions in store/models.py, connection.py, settings.py - Type all functions in network_status/abc.py, darwin.py, network_manager.py - Type all methods in scheduler.py - Add [[tool.mypy.overrides]] with disallow_untyped_defs=true for clean modules - Fix incorrect return type in settings.py (List[Dict[str,str]] -> list[dict[str,Any]]) - Fix implicit Optional and bare return in network_manager.py
0427b6d to
eeec8b3
Compare
|
i guess pyright (Microsoft) and pyre (Meta). pyright is pretty popular but its PyQt6 stub support isn't as mature as mypy's yet, and pyre has a smaller community around it. Either way the annotations are just standard Python, so switching checkers later is no big deal if something better comes along. Btw rebased this onto current master — the requires-python bump from #2384 and the network changes from #2176 are now incorporated. So this PR just adds the mypy config + annotations on top. |
Description
Phases 1+2 of #2362 — sets up mypy infrastructure and adds type annotations to core modules.
Phase 1 (infrastructure):
requires-pythonfrom>=3.8to>=3.10(3.8/3.9 are EOL)pyproject.tomlmypy,PyQt6-stubs,types-peeweeto dev dependenciescontinue-on-error: true)py.typedmarker file (PEP 561)Phase 2 (core module annotations):
from __future__ import annotationsto all core modules (PEP 563)store/models.py,connection.py,settings.py,migrations.pynetwork_status/abc.py,darwin.py,network_manager.pyscheduler.pydisallow_untyped_defs = true) for fully clean modulessettings.pynetwork_manager.pyNotes:
warn_return_anyandcheck_untyped_defsset tofalseinitially — enabling them surfaces 100+ errors in unannotated modules. Will be tightened in Phase 5.migrations.pyexcluded from strict override — Peewee's_metatable name access generates ~30 false positives from incomplete type stubs.scheduler.pyannotated but not in strict override — ScheduleStatus construction needs refactoring before strict enforcement.Related Issue
Partial implementation of #2362 (Phases 1+2 of 5)
Motivation and Context
The codebase has inconsistent type annotations with no type checker enforcing correctness. This PR adds infrastructure and annotates the core modules as a foundation for gradually typing the rest of the codebase.
How Has This Been Tested?
uv run mypy src/vorta/store/ src/vorta/network_status/— 0 errors on strict modulesuv run pre-commit run --all-files— all hooks passuv run mypy src/vorta— runs without crashes (179 errors, all in future-phase modules)Types of changes
Checklist:
I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.