Things to check first
Feature description
As a result of researching why the import of the inflect library was slow I found out that the @typechecked decorator was the main reason.
See jaraco/inflect#212
I believe that the same solution suggested in this issue can also be applied generally, the solution being to defer running the typechecked decorator until the decorated function is actually called, and to cache the result of the "decoration" as otherwise every call to the decorated function will be slow
Something like this:
@functools.cache
def cached_typechecked(func: Callable) -> Callable:
return typechecked(func)
def lazy_typechecked(func: Callable) -> Callable:
def wrapper(*args, **kwargs) -> Any:
typechecked_func = cached_typechecked(func)
return typechecked_func(*args, **kwargs)
return wrapper
Use case
Faster imports for all direct and indirect users of typeguard
Things to check first
Feature description
As a result of researching why the import of the
inflectlibrary was slow I found out that the@typecheckeddecorator was the main reason.See jaraco/inflect#212
I believe that the same solution suggested in this issue can also be applied generally, the solution being to defer running the typechecked decorator until the decorated function is actually called, and to cache the result of the "decoration" as otherwise every call to the decorated function will be slow
Something like this:
Use case
Faster imports for all direct and indirect users of typeguard