Skip to content

fix: arun() returns CrawlResult directly for proper IDE type support (#1898)#1957

Open
ntohidi wants to merge 1 commit intodevelopfrom
fix/arun-return-type-1898
Open

fix: arun() returns CrawlResult directly for proper IDE type support (#1898)#1957
ntohidi wants to merge 1 commit intodevelopfrom
fix/arun-return-type-1898

Conversation

@ntohidi
Copy link
Copy Markdown
Collaborator

@ntohidi ntohidi commented May 5, 2026

Summary

  • Fixes [Bug]: arun() and arun_many() type hinting needs fixing #1898: arun() now returns CrawlResult directly instead of wrapping in CrawlResultContainer. This lets Pylance/Pyright see .markdown, .html, and all other CrawlResult attributes without errors.
  • CrawlResultContainer uses __getattr__ proxy which is invisible to static type checkers — so even though the code worked at runtime, IDEs couldn't autocomplete or validate attribute access.
  • Deep crawl streaming (via DeepCrawlDecorator) is unaffected — it overrides the return type to AsyncGenerator regardless.

Changes

  • crawl4ai/async_webcrawler.py: Return CrawlResult directly from all three return paths in arun()
  • tests/test_type_annotations.py: Updated test to verify arun() is annotated as -> CrawlResult

Test plan

  • arun() returns CrawlResult instance directly (verified with isinstance())
  • All 11 type annotation tests pass
  • All 9 deep crawl ContextVar tests pass (streaming unaffected)
  • Live crawl of example.com works with result.markdown access

…ner (#1898)

CrawlResultContainer proxies attributes via __getattr__ which is invisible
to type checkers. Since arun() always returns a single result, return
CrawlResult directly so Pylance/Pyright can see .markdown, .html, etc.

Deep crawl streaming (via DeepCrawlDecorator) still returns an
AsyncGenerator — that path is unaffected.
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.

1 participant