crawlee-python icon indicating copy to clipboard operation
crawlee-python copied to clipboard

Add package for run-time type checking

Open vdusek opened this issue 1 year ago • 2 comments

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 hook typeguard.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 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.

vdusek avatar Jan 16 '24 15:01 vdusek