opentelemetry-instrumentation-genai-qwen-agent: support strict typing - #366
opentelemetry-instrumentation-genai-qwen-agent: support strict typing#366Yigtwxx wants to merge 3 commits into
Conversation
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
Pull request dashboard statusWaiting on maintainers · refreshed 2026-08-08 06:46 UTC Merge when ready. Status above doesn't look right?
|
There was a problem hiding this comment.
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 itstests/andexamples/from type checking. - Resolved Pyright strict-mode narrowing issues in
qwen_agent/utils.pyby castingdict/listvalues afterisinstance(...)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. |
| responded: set[str] = set() | ||
| pending: list[str] = [] | ||
| for msg in messages: | ||
| for msg in cast(list[Any], messages): |
There was a problem hiding this comment.
can we do even better and specify the type of elements?
There was a problem hiding this comment.
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.
Description
Adds
opentelemetry-instrumentation-genai-qwen-agentto the[tool.pyright]includelist, per the progressive rollout the config already describes, and excludes itstests/andexamples/like the other covered packages.Strict mode reported eight errors, all in
utils.pyand all the same shape:isinstance(x, dict)/isinstance(x, list)narrowing todict[Unknown, Unknown]/list[Unknown]. They are narrowed withcast(dict[str, Any], ...)andcast(list[Any], ...), matching the idiom already used inopentelemetry-instrumentation-genai-agno. No behavior change and no new public surface.The package was already listed in the
typechecktox env deps, so notox.inichange is needed.Related to #169
Type of change
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 passedtox -e py310-test-instrumentation-genai-qwen-agent-oldest— 21 passed, 1 skippedtox -e lint-instrumentation-genai-qwen-agentandtox -e precommitThe 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.