perf: Conditional imports for dependencies only used for type checks
Metadata
Current evaluation
Merged #1151 (commit 2776050f) by maintainer upils: added 3 lint rules flagging imports used only for type checks and wrapped selected dependency imports in deferred type-checking blocks. Approved by 3 reviewers; all CI checks passed.
Resolution: closed resolved
Reason: PR #1151 was merged into main as commit 2776050f after approval by 3 reviewers with all CI checks passing, introducing three linter rules for type-check-only imports and converting selected dependency imports to deferred type-checking form.
Evaluated by: mr-cal-bot
No scores available.
Issue body
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [ ] Have you added an entry to the changelog (`docs/reference/changelog.rst`)?
-----
Add 3 linter rules to check for imports for dependencies only used for type checks.
Fixes errors found by these rules (and 2 other unrelated lint errors).
Also rely on deferred type checking to import some deps only for type checking. These are not currently helping to reduce import time (because the same deps are imported in other modules) but I am experimenting to see if we could foster this habit and over time avoid some imports at runtime.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged #1151 (commit 2776050f) by maintainer upils: added 3 lint rules flagging imports used only for type checks and wrapped selected dependency imports in deferred type-checking blocks. Approved by 3 reviewers; all CI checks passed. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged #1151, adding three lint rules for type-check-only imports and moving selected dependency imports into deferred type-checking blocks. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged after approval by three reviewers and passing all CI checks. The PR adds linter rules for type-check-only imports and implements deferred imports to optimize runtime performance. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged by maintainer upils. Added three linter rules to enforce conditional imports for type-only dependencies, resolved associated lint errors, and implemented deferred type checking to experiment with reducing runtime import overhead. |
Update history
No update history recorded yet.
Related work
-
Related To:
canonical/craft-parts#1294
(confidence 45%)
Later commit bb62329e enabled strict type checking with pyright, extending the same typing/import hygiene effort started here.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #797 perf: add TC001/2/3 linter rules to check imports | craft-application | merged | Merged PR #797 in commit 5a49fd57, enabling TC001–TC003 import checks and correcting violations across 29 files for more precise import handling. |