Repository navigation
docs(examples): fix pyright errors in agentic examples - #568
Merged
leandrodamascena merged 3 commits intoNov 1, 2026
Merged
Conversation
Scope reportMissingImports=false to the agentic examples and the FastAPI example through pyright execution environments, since smolagents, pydantic_ai, strands and fastapi are not dev dependencies. Add None checks for T | None attribute values, narrow S3Attribute values to S3Value before reading the key, use sync_ table helpers in sync code and await the async ones, and replace raw expression strings in query and scan calls with partition_key and Condition objects. Also add the missing Employee.email attribute and stop iterating a query result twice in smolagents_numbers.py.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
@leandrodamascena ready for review, duplications sonar fails on are intentional because examples should stand on its own docs |
Member
|
Thanks @vicolby! I pushed a fix for the Bedrock setup and the docstrings smolagents needs. All 11 examples now import with the frameworks installed, Pyright is clean, and the LocalStack checks passed. I agree about the duplication; these examples should stand on their own. Looks good to me 🙂 |
|
leandrodamascena
approved these changes
Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Intent
Part of #325 (support strict type checking for mypy, pyright and ty). Fix the agentic examples (53 errors) and the fastapi import in async/. Measured on upstream main cdd8c85 (2026-10-25): type_checking/crud_types.py is already clean. docs/examples/agentic/ has 53 pyright errors: 14 missing third-party imports (smolagents, pydantic_ai, strands; add pyright reportMissingImports=false), 26
T | Noneattribute values used directly, 7 calls not awaited, 4 S3, 2 other (Employee.emailin agentic/smolagents_encrypted.py:29, positionalsync_scanargs in agentic/strands_crud.py:110). Plus 1 missing fastapi import in docs/examples/async/. Decided: keep attributes typedT | Noneand add None checks in the examples. The S3Attribute library typing gap was fixed in #533.What Changed
best_practices,pydantic_ai_*,smolagents_*,strands_*) to pass pyright. Optional attribute values now getNonechecks or defaults (for exampledoc.sk or "",emp.ssn is not None and ...). TheS3Valuenarrowing uses anisinstanceassert.Employeenow declares theemailattribute it uses.partition_key=,sort_key_condition=Order.sk.begins_with(...)andfilter_condition=Order.status == .... This replaces the raw expression strings and removes the positionalsync_scanarguments instrands_crud.py. Optional tool parameters are now typedstr | None.[[tool.pyright.executionEnvironments]]entries inpyproject.tomlfordocs/examples/agenticanddocs/examples/async/fastapi_example.py. They setreportMissingImports = false, because the example-only packages (smolagents, pydantic_ai, strands, fastapi) are not dev dependencies.Part of #325.
Risk Assessment
✅ Low: The change only touches documentation example files and a pyright config block. Pyright run with python/ on the path reports 0 errors under docs/examples/agentic and resolves the fastapi import. The rewritten query/scan calls match the real Model.sync_query/sync_scan signatures, and the S3 assertions hold at runtime because save() replaces S3File with S3Value.
Testing
I built the extension with maturin and ran pyright 1.1.414 on the base commit (7f133f4) and the target commit. At base, docs/examples/agentic, async/fastapi_example.py and type_checking reported 53 errors; at the target they report 0. I then ran the real example modules against pydynox's in-memory backend with pass-through stubs for the strands and smolagents
tooldecorators. The rewritten query and scan calls and the None-safe sums all gave correct results. Running pyright over all of docs/examples/async also shows 4 errors in model_async.py, query_async.py and real_world.py (e.g.AsyncQueryResult.all); those files are outside this change's scope.Evidence: pyright on target, scoped to the changed examples
Evidence: pyright on base commit
Evidence: Runtime driver output (in-memory backend)
Evidence: Runtime driver script
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
uv run --with maturin maturin developuvx pyright --pythonpath .venv/bin/python docs/examples/agentic docs/examples/async/fastapi_example.py docs/examples/type_checking (target: 0 errors)same pyright command on base 7f133f4 archive (53 errors)uvx pyright over docs/examples/async (4 unrelated errors in other files)Runtime driver script executing strands_crud, best_practices, smolagents_numbers and smolagents_encrypted under MemoryBackenddocs/examples/async/model_async.py:24- Pyright still reports 4 errors in other docs/examples/async files (model_async.py Optional access, and .all on AsyncQueryResult in query_async.py and real_world.py). They are outside this change's scope (agentic examples and the fastapi import). Fixing them would be a follow-up under issue 325. docs/guides/type-checking.md is being rewritten in PR 567.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.