Commit 46c3748
feat(orm): type QueryBuilder.get() as Collection[TModel]
Make the ORM Collection generic (Collection[T]) with TYPE_CHECKING-only
element-access stubs (first/__iter__/__getitem__), and annotate
QueryBuilder.get()/get_models() to return Collection[TModel]. So
`User.where(...).get()` now types as Collection[User] instead of Any,
and element access (iteration, indexing, first()) yields User.
- load() gets one `# type: ignore` (runs only on model collections, but
the ORM Collection is legitimately generic over non-model values too).
- chunk_by_id uses results[-1] (equivalent; non-emptiness already
guaranteed) so the last row is cleanly typed.
Stubs are typing-only; runtime behaviour is unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 1fe875d commit 46c3748
2 files changed
Lines changed: 19 additions & 4 deletions
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
3 | 16 | | |
4 | | - | |
5 | 17 | | |
6 | 18 | | |
7 | 19 | | |
| |||
27 | 39 | | |
28 | 40 | | |
29 | 41 | | |
30 | | - | |
| 42 | + | |
| 43 | + | |
31 | 44 | | |
32 | 45 | | |
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
161 | | - | |
| 162 | + | |
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| |||
458 | 459 | | |
459 | 460 | | |
460 | 461 | | |
461 | | - | |
| 462 | + | |
| 463 | + | |
462 | 464 | | |
463 | 465 | | |
464 | 466 | | |
| |||
0 commit comments