Skip to content

Conversation

@mshsheikh
Copy link
Contributor

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 suppressions

**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 suppressions
Added type ignore comment for item_id assignment.
@seratch
Copy link
Member

seratch commented Oct 16, 2025

Thanks for sending this, but I am not sure if having lots of cast is a good idea here.

…ior unchanged.

- Replace multiple per-item casts in get_items by accumulating plain dicts and applying a single cast at the return so the function matches its annotated return type while keeping runtime behavior identical.​

- Retain a focused type ignore for item_id in pop_item because the TypedDict union does not guarantee an id key even though the API does, avoiding broader casts or schema changes in this small patch.​

- Preserve ordering, pagination, and session behavior; no public API changes, no control-flow changes, and no added dependencies, making the change safe and easy to review.
@seratch seratch marked this pull request as draft October 17, 2025 04:31
@github-actions
Copy link
Contributor

This PR is stale because it has been open for 10 days with no activity.

@github-actions github-actions bot added the stale label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants