Commit dfa0f37
authored
Fix type safety in OpenAIConversationsSession.get_items()
**What This PR Fixes**
- Resolves type mismatch where `get_items()` returned `list[dict]` but was annotated as `list[TResponseInputItem]`
- Removes unnecessary `# type: ignore` comments that masked real type safety issues
- Adds explicit non-None assertion for client initialization in `start_openai_conversations_session`
**Changes Made**
- Added `from typing import cast` import to support explicit type casting
- Typed the `all_items` accumulator as `list[TResponseInputItem]` to match method signature
- Cast `item.model_dump(exclude_unset=True)` results to `TResponseInputItem` in both iteration branches
- Removed `# type: ignore` on `get_items()` return statement since type now matches annotation
- Removed `# type: ignore [typeddict-item]` in `pop_item()` since items are now correctly typed
- Added explicit `assert _maybe_openai_client is not None` in `start_openai_conversations_session` to document invariant
**Why This Matters**
- Enables proper static type checking with mypy and other type checkers
- Prevents potential runtime errors when downstream code expects proper `TResponseInputItem` objects
- Makes type contracts explicit and verifiable
- Improves code maintainability without changing runtime behavior
**Backward Compatibility**
- No changes to public APIs or method signatures
- No changes to pagination, ordering, or session management behavior
- All existing functionality preserved
**Testing**
- Existing test suite validates unchanged behavior
- Type checking now passes without suppressions1 parent cfddc7c commit dfa0f37
1 file changed
+10
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | | - | |
16 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
46 | | - | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | | - | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
61 | | - | |
| 64 | + | |
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
66 | | - | |
| 69 | + | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
| |||
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
80 | | - | |
| 83 | + | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| |||
0 commit comments