Crawlee—A web scraping and browser automation library for Python to build reliable crawlers. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with BeautifulSoup, Playwright, and raw HTTP. Both headful and headless mode. With proxy rotation.
E.g. typeguard, it can be applied either using a decorator @typechecked for a specific function or import hook typeguard.install_import_hook() for the whole module.
I suppose it is implemented by using typing.get_type_hints for getting the type hints for a specific function. I run into a bug when typing.get_type_hints and from __future__ import annotations are used together, see the issue https://github.com/apify/apify-sdk-python/issues/151. However, tests should reveal it.
Description
Based on the PR https://github.com/apify/apify-sdk-python/pull/171, @janbuchar suggested the usage of some run-time checking for Python.
E.g. typeguard, it can be applied either using a decorator
@typechecked
for a specific function or import hooktypeguard.install_import_hook()
for the whole module.For some methods/functions where we check manually the type of args/return type it could make sense to use it. E.g. here https://github.com/apify/apify-sdk-python/blob/v1.5.1/src/apify/scrapy/utils.py#L44.
Potential problems
I suppose it is implemented by using
typing.get_type_hints
for getting the type hints for a specific function. I run into a bug whentyping.get_type_hints
andfrom __future__ import annotations
are used together, see the issue https://github.com/apify/apify-sdk-python/issues/151. However, tests should reveal it.