Skip to content

fix: correct arun() return type annotation (#1898)#1901

Open
hafezparast wants to merge 1 commit intounclecode:developfrom
hafezparast:fix/maysam-arun-type-hint-1898
Open

fix: correct arun() return type annotation (#1898)#1901
hafezparast wants to merge 1 commit intounclecode:developfrom
hafezparast:fix/maysam-arun-type-hint-1898

Conversation

@hafezparast
Copy link
Copy Markdown
Contributor

Summary

arun() was annotated as returning RunManyReturn (which is Union[CrawlResultContainer, AsyncGenerator]), but it always returns CrawlResultContainer. This caused Pylance/Pyright to flag result.markdown as an error because AsyncGenerator doesn't have that attribute.

Fixes #1898

The Bug

result = await crawler.arun(url="https://example.com")
result.markdown  # IDE shows error: "markdown" doesn't exist on AsyncGenerator

Code works fine at runtime — Python ignores type hints. But the IDE red squiggly confuses users.

The Fix

# Before
async def arun(self, url, config=None, **kwargs) -> RunManyReturn:  # includes AsyncGenerator

# After
async def arun(self, url, config=None, **kwargs) -> CrawlResultContainer:  # what it actually returns

arun_many() keeps RunManyReturn — it does return AsyncGenerator when stream=True.

Regression guard

Adds tests/test_type_annotations.py — 11 tests that catch annotation mismatches using static introspection (no pyright/mypy needed in CI):

  • Return type includes types the method never returns
  • Missing return annotations on public methods
  • Missing parameter annotations
  • Return annotation doesn't include the actual return type
  • Config init params match stored attributes
  • Public types are importable

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

  • 11 annotation tests passing
  • Existing pipeline tests pass (16/16)
  • All CrawlResultContainer usage patterns verified (attribute access, iteration, indexing)

🤖 Generated with Claude Code

…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>
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