[Bug]: arun() and arun_many() type hinting needs fixing
crawl4ai version
0.8.6
Expected Behavior
Something like this
Current Behavior
Is this reproducible?
Yes
Inputs Causing the Bug
RunManyReturn = Union[
CrawlResultContainer[CrawlResultT],
AsyncGenerator[CrawlResultT, None]
]
`arun()` is not an async generator, maybe you guys give it generator properties through CrawlResultContainer but the typing needs fixing.
Steps to Reproduce
I am using Pylance, I tried Pyrefly from meta too.
Code snippets
import asyncio
from crawl4ai import *
async def main():
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(
url="https://www.nbcnews.com/business",
)
print(result.markdown)
if __name__ == "__main__":
asyncio.run(main())
OS
Windows
Python version
3.13.11
Browser
No response
Browser version
No response
Error logs & Screenshots (if applicable)
No response
Fixed in PR #1901. arun() was annotated as RunManyReturn (includes AsyncGenerator) but always returns CrawlResultContainer. Changed to CrawlResultContainer — Pylance/Pyright should stop flagging result.markdown as an error.
Also added test_type_annotations.py — static analysis tests that catch this class of bug without needing pyright in CI. A full pyright scan found 46 return type mismatches across the codebase; this PR fixes the user-facing one and guards against future regressions.
pip install git+https://github.com/hafezparast/crawl4ai.git@fix/maysam-arun-type-hint-1898
There is similar issue for arun_many() too.
Hi, I'd like to work on this. I'll submit a PR shortly.
@luzede Fixed in PR #1901 and merged into the develop branch. arun() now correctly returns CrawlResultContainer instead of RunManyReturn, so Pylance/Pyright will no longer flag result.markdown as an error. Will be in the next release.
@ntohidi I reviewed that pr, it does not really solve it because CrawlResultContainer does not inherit CrawlResult class attributes, and does not have access to those. Also same issue on the arun_many(). The typing needs overhaul. I would make a pr for it but I don't know what the end result of arun() and arun_many() should be, the container from what I understand gives array like attributes to a crawlresult, maybe it is necessary maybe it is an extra that should be removed.
I would change both the typing and what the functions actually return.
@luzede Good catch — you're right that PR #1901 didn't fully solve it. CrawlResultContainer uses __getattr__ which is invisible to type checkers.
PR #1957 fixes this properly: arun() now returns CrawlResult directly instead of wrapping in CrawlResultContainer. Pylance/Pyright will see .markdown, .html, and all other attributes correctly.
arun_many() still uses CrawlResultContainer — that's a separate issue since it genuinely needs list-like behavior. We'll address that separately if needed.
This has been fixed and is available in the latest release, v0.9.1.