fix: correct arun() return type annotation (#1898)#1901
Open
hafezparast wants to merge 1 commit intounclecode:developfrom
Open
fix: correct arun() return type annotation (#1898)#1901hafezparast wants to merge 1 commit intounclecode:developfrom
hafezparast wants to merge 1 commit intounclecode:developfrom
Conversation
…ainer (unclecode#1898) arun() always returns CrawlResultContainer, never AsyncGenerator. The RunManyReturn type (Union[CrawlResultContainer, AsyncGenerator]) caused Pylance/Pyright to flag result.markdown as an error because AsyncGenerator doesn't have that attribute. Also adds test_type_annotations.py — 11 static analysis tests that catch annotation mismatches (return types, missing annotations, export checks) without needing pyright in CI. Would have caught this bug before it was reported. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
arun()was annotated as returningRunManyReturn(which isUnion[CrawlResultContainer, AsyncGenerator]), but it always returnsCrawlResultContainer. This caused Pylance/Pyright to flagresult.markdownas an error becauseAsyncGeneratordoesn't have that attribute.Fixes #1898
The Bug
Code works fine at runtime — Python ignores type hints. But the IDE red squiggly confuses users.
The Fix
arun_many()keepsRunManyReturn— it does returnAsyncGeneratorwhenstream=True.Regression guard
Adds
tests/test_type_annotations.py— 11 tests that catch annotation mismatches using static introspection (no pyright/mypy needed in CI):A pyright scan found 46 return type mismatches across the codebase. This PR fixes the user-facing one (#1898) and adds the test guard to prevent future regressions.
Test plan
🤖 Generated with Claude Code