Skip to content

ci: Add openai to uv typing group - #7334

Merged
alexander-alderman-webb merged 14 commits into
masterfrom
webb/openai/mypy
Sep 3, 2026
Merged

ci: Add openai to uv typing group#7334
alexander-alderman-webb merged 14 commits into
masterfrom
webb/openai/mypy

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Description

Add openai to the typing dependency group and fix the resulting mypy errors.

Resolves:

sentry_sdk/ai/_openai_completions_api.py:46: error: Incompatible return value type (got "list[object]", expected "list[str]")  [return-value]
sentry_sdk/integrations/openai.py:69: error: Module "openai.types.responses" has no attribute "SequenceNotStr"  [attr-defined]
sentry_sdk/integrations/openai.py:83: error: Cannot assign to a type  [misc]
sentry_sdk/integrations/openai.py:83: error: Incompatible types in assignment (expression has type "None", variable has type "type[NotGiven]")  [assignment]
sentry_sdk/integrations/openai.py:88: error: Cannot assign to a type  [misc]
sentry_sdk/integrations/openai.py:88: error: Incompatible types in assignment (expression has type "None", variable has type "type[Omit]")  [assignment]
sentry_sdk/integrations/openai.py:130: error: Cannot assign to a method  [method-assign]
sentry_sdk/integrations/openai.py:131: error: Cannot assign to a method  [method-assign]
sentry_sdk/integrations/openai.py:135: error: Cannot assign to a method  [method-assign]
sentry_sdk/integrations/openai.py:136: error: Cannot assign to a method  [method-assign]
sentry_sdk/integrations/openai.py:139: error: Cannot assign to a method  [method-assign]
sentry_sdk/integrations/openai.py:140: error: Cannot assign to a method  [method-assign]
sentry_sdk/integrations/openai.py:219: error: Argument 1 to "_get_text_items" has incompatible type "str | Iterable[ChatCompletionContentPartTextParam | ChatCompletionContentPartImageParam | ChatCompletionContentPartInputAudioParam | File] | Iterable[ChatCompletionContentPartTextParam | ChatCompletionContentPartRefusalParam]"; expected "str | Iterable[ChatCompletionContentPartTextParam | ChatCompletionContentPartImageParam | ChatCompletionContentPartInputAudioParam | File]"  [arg-type]
sentry_sdk/integrations/openai.py:433: error: Argument 1 to "_transform_system_instructions" has incompatible type "list[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | <27 more items>]"; expected "list[ChatCompletionSystemMessageParam]"  [arg-type]
sentry_sdk/integrations/openai.py:461: error: Argument 1 to "normalize_message_roles" has incompatible type "list[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | <27 more items>]"; expected "list[dict[str, Any]]"  [arg-type]
sentry_sdk/integrations/openai.py:573: error: Argument 1 to "_transform_system_instructions" has incompatible type "list[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam]"; expected "list[ChatCompletionSystemMessageParam]"  [arg-type]
sentry_sdk/integrations/openai.py:582: error: Argument 1 to "normalize_message_roles" has incompatible type "list[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam]"; expected "list[dict[str, Any]]"  [arg-type]
sentry_sdk/integrations/openai.py:861: error: Argument "messages" to "_wrap_synchronous_completions_chunk_iterator" has incompatible type "Any | list[str] | None"; expected "Iterable[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam] | None"  [arg-type]
sentry_sdk/integrations/openai.py:941: error: Argument "messages" to "_wrap_asynchronous_completions_chunk_iterator" has incompatible type "Any | list[str] | None"; expected "Iterable[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam] | None"  [arg-type]
sentry_sdk/integrations/openai.py:1143: error: Argument 1 to "append" of "list" has incompatible type "str | Any | Delta"; expected "str"  [arg-type]
sentry_sdk/integrations/openai.py:1216: error: Argument 1 to "append" of "list" has incompatible type "str | Any | Delta"; expected "str"  [arg-type]
sentry_sdk/integrations/openai.py:1525: error: Argument "input" to "_wrap_synchronous_responses_event_iterator" has incompatible type "Any | list[str] | None"; expected "str | list[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | <27 more items>] | None"  [arg-type]
sentry_sdk/integrations/openai.py:1595: error: Argument "input" to "_wrap_asynchronous_responses_event_iterator" has incompatible type "Any | list[str] | None"; expected "str | list[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | <27 more items>] | None"  [arg-type]
pyproject.toml: note: unused section(s): module = ['agents.*', 'anthropic.*', 'arq.*', 'asttokens.*', 'blinker.*', 'celery.app.trace', 'cohere.*', 'dramatiq.*', 'executing.*', 'flask.signals', 'google.genai.*', 'grpc.*', 'huey.*', 'huggingface_hub.*', 'langchain.*', 'langchain_core.*', 'langgraph.*', 'openfeature.*', 'pure_eval.*', 'pyramid.*', 'pyspark.*', 'rq.*', 'sanic.*', 'tornado.*']
Found 23 errors in 2 files (checked 1 source file)

Issues

closes #7020

Reminders

@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review September 2, 2026 07:35
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code owner September 2, 2026 07:36
Comment thread sentry_sdk/integrations/openai.py Outdated
Comment thread sentry_sdk/integrations/openai.py
Comment thread sentry_sdk/integrations/openai.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 14104d1. Configure here.

Comment thread sentry_sdk/integrations/openai.py Outdated
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

130462 passed | ⏭️ 7110 skipped | Total: 137572 | Pass Rate: 94.83% | Execution Time: 469m 23s

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests 📈 +1
Failed Tests 📉 -1
Skipped Tests

➖ Removed Tests (1)

View removed tests
  • test_continuous_profiler_auto_start_and_stop_sampled_span_streaming[non-experiment-thread]
    • File: tests.profiler.test_continuous_profiler

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2505 uncovered lines.
✅ Project coverage is 90.25%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/openai.py 100.00% ⚠️ 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    90.24%    90.25%    +0.01%
==========================================
  Files          193       193         —
  Lines        25685     25689        +4
  Branches      9474      9474         —
==========================================
+ Hits         23178     23184        +6
- Misses        2507      2505        -2
- Partials      1438      1436        -2

Generated by Codecov Action

Base automatically changed from webb/openai/fix-responses-instructions to master September 3, 2026 08:01
@alexander-alderman-webb alexander-alderman-webb changed the title ci: Add openai to uv typing group ci: Add openai to uv typing group Sep 3, 2026
@alexander-alderman-webb
alexander-alderman-webb merged commit 45fdae4 into master Sep 3, 2026
159 checks passed
@alexander-alderman-webb
alexander-alderman-webb deleted the webb/openai/mypy branch September 3, 2026 08:16
Comment on lines +1331 to +1333
def _wrap_chat_completion_create(
f: "Callable[..., Union[ChatCompletion, Stream[ChatCompletionChunk]]]",
) -> "Callable[..., Coroutine[Any, Any, Union[ChatCompletion, Stream[ChatCompletionChunk]]]]":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_wrap_chat_completion_create claims a Coroutine return type for a sync wrapper

The return annotation of _wrap_chat_completion_create should be a sync Callable returning Union[ChatCompletion, Stream[ChatCompletionChunk]], not Coroutine[...]; as written it types the sync Completions.create patch as async.

Evidence
  • _wrap_chat_completion_create returns _sentry_patched_create_sync, a plain def that calls _new_sync_chat_completion and returns its result directly.
  • The annotated return type is Callable[..., Coroutine[Any, Any, Union[ChatCompletion, Stream[ChatCompletionChunk]]]].
  • The matching async helper _wrap_async_chat_completion_create correctly uses Coroutine[...]; the sync helper should mirror _new_sync_chat_completion's non-coroutine return type instead.

Identified by Warden · find-bugs · QFC-W6J

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add openai to typing group

2 participants