Skip to content

opentelemetry-instrumentation-genai-qwen-agent: support strict typing - #366

Open
Yigtwxx wants to merge 3 commits into
open-telemetry:mainfrom
Yigtwxx:chore/qwen-agent-strict-typing
Open

opentelemetry-instrumentation-genai-qwen-agent: support strict typing#366
Yigtwxx wants to merge 3 commits into
open-telemetry:mainfrom
Yigtwxx:chore/qwen-agent-strict-typing

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Aug 7, 2026

Copy link
Copy Markdown

Description

Adds opentelemetry-instrumentation-genai-qwen-agent to the [tool.pyright] include list, per the progressive rollout the config already describes, and excludes its tests/ and examples/ like the other covered packages.

Strict mode reported eight errors, all in utils.py and all the same shape: isinstance(x, dict) / isinstance(x, list) narrowing to dict[Unknown, Unknown] / list[Unknown]. They are narrowed with cast(dict[str, Any], ...) and cast(list[Any], ...), matching the idiom already used in opentelemetry-instrumentation-genai-agno. No behavior change and no new public surface.

The package was already listed in the typecheck tox env deps, so no tox.ini change is needed.

Related to #169

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested?

  • tox -e typecheck — 0 errors (was 8 with the package included and unfixed)
  • tox -e py311-test-instrumentation-genai-qwen-agent-latest — 22 passed
  • tox -e py310-test-instrumentation-genai-qwen-agent-oldest — 21 passed, 1 skipped
  • tox -e lint-instrumentation-genai-qwen-agent and tox -e precommit

The existing tests are unchanged, which is the evidence that the narrowing did not alter behavior.

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

Add the package to the pyright include list and exclude its tests and
examples, following the progressive rollout the config already describes.

Strict mode reported eight errors in utils.py, all from isinstance()
narrowing producing dict[Unknown, Unknown] / list[Unknown]. Narrow those
with cast(dict[str, Any], ...) and cast(list[Any], ...), matching the
existing idiom in the agno package. No behavior change.

Assisted-by: Claude Opus 5
@Yigtwxx
Yigtwxx requested a review from a team as a code owner August 7, 2026 16:45
Copilot AI lite review requested due to automatic review settings August 7, 2026 16:45
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 7, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 7, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-08-08 06:46 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

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.

Pull request overview

This PR expands the repository’s strict Pyright coverage to include opentelemetry-instrumentation-genai-qwen-agent, addressing strict-mode type errors by adding explicit cast(...)-based narrowing in utils.py without changing runtime behavior.

Changes:

  • Added the Qwen-Agent instrumentation package to [tool.pyright].include, and excluded its tests/ and examples/ from type checking.
  • Resolved Pyright strict-mode narrowing issues in qwen_agent/utils.py by casting dict/list values after isinstance(...) checks.
  • Added a towncrier changelog fragment documenting the stricter typing coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
pyproject.toml Includes the Qwen-Agent package in Pyright strict checking and excludes its tests/examples to match the repo’s rollout pattern.
instrumentation/opentelemetry-instrumentation-genai-qwen-agent/src/opentelemetry/instrumentation/genai/qwen_agent/utils.py Adds cast(...) to satisfy strict typing for dict/list narrowing in message conversion helpers.
instrumentation/opentelemetry-instrumentation-genai-qwen-agent/.changelog/366.added Documents that the package is now covered by the repo’s Pyright configuration.

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice!

responded: set[str] = set()
pending: list[str] = []
for msg in messages:
for msg in cast(list[Any], messages):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we do even better and specify the type of elements?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 1131e05 — the casts are gone entirely.

Instead of cast(list[Any], ...) I annotated the signatures with
qwen-agent's own Message / ContentItem, imported under
TYPE_CHECKING since qwen-agent is an optional dependency. Pyright
narrows the isinstance checks on its own from there, so all five
list casts dropped out.

The only cast left is the dict[str, Any] one in _field_value,
where the lookup genuinely is a heterogeneous mapping.

The strict-mode narrowing was done with cast(list[Any], ...), which
satisfies pyright but throws away the element type. qwen-agent's own
Message and ContentItem describe those elements, so annotate the
signatures with them (under TYPE_CHECKING, since qwen-agent is an
optional dependency) and let pyright narrow the isinstance checks on
its own. All five list casts are gone as a result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants