Closed
Description
Dear typeshed team,
I have run into the following typing issue when using contextlib.ContextDecorator
and analysing via mypy:
# minimal example
from contextlib import ContextDecorator
class MyDecorator(ContextDecorator):
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
pass
@MyDecorator()
def func() -> int:
return 1
Returns the following Error:
/scratch.py:10: error: Argument 1 to "__call__" of "ContextDecorator" has incompatible type "Callable[[], int]"; expected "Callable[..., None]"
Found 1 error in 1 file (checked 1 source file)
I believe the current typeshed annotation is incorrect:
typeshed/stdlib/2and3/contextlib.pyi
Lines 67 to 68 in 5d553c9
I think it should be:
class ContextDecorator:
def __call__(self, func: Callable[..., Any]) -> Callable[..., Any]: ...
That would make it consistent with the `functool.wraps` annotation:
typeshed/stdlib/3/functools.pyi
Lines 56 to 58 in 5d553c9
which is used in the contextlib.ContextDecorator.__call__
implementation:
https://github.com/python/cpython/blob/cadda52d974937069eeebea1cca4229e2bd400df/Lib/contextlib.py#L75-L80
I'd be happy to submit a PR if my error analysis is correct.
Cheers,
Andreas 😃
Metadata
Metadata
Assignees
Labels
No labels