From ee52217840748afd78eb4479fe2c8ea5c7ed896c Mon Sep 17 00:00:00 2001 From: Tom Schraitle Date: Mon, 21 Nov 2022 08:38:22 +0100 Subject: [PATCH] Doc: Add Optional in Decorator factories mypy complains about error: Incompatible default for argument "__func" (default has type "None", argument has type "Callable[..., Any]") [assignment] note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True This change adds Optional around "Callable[..., Any]] = None" --- docs/source/generics.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/generics.rst b/docs/source/generics.rst index 9a13e2a955c4..a5c7b8accaa8 100644 --- a/docs/source/generics.rst +++ b/docs/source/generics.rst @@ -724,7 +724,7 @@ achieved by combining with :py:func:`@overload `: .. code-block:: python - from typing import Any, Callable, TypeVar, overload + from typing import Any, Callable, Optional, TypeVar, overload F = TypeVar('F', bound=Callable[..., Any]) @@ -736,7 +736,7 @@ achieved by combining with :py:func:`@overload `: def atomic(*, savepoint: bool = True) -> Callable[[F], F]: ... # Implementation - def atomic(__func: Callable[..., Any] = None, *, savepoint: bool = True): + def atomic(__func: Optional[Callable[..., Any]] = None, *, savepoint: bool = True): def decorator(func: Callable[..., Any]): ... # Code goes here if __func is not None: