From 42e61612c2398709095af6c1c2b849aa4898fb0f Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Thu, 16 Dec 2021 12:40:02 +0100 Subject: [PATCH 1/4] Logger.getChild subclass compatible typehint --- stdlib/logging/__init__.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 70d6a1fda2fc..88ce60b79e71 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -15,6 +15,7 @@ _ArgsType = Union[Tuple[object, ...], Mapping[str, object]] _FilterType = Union[Filter, Callable[[LogRecord], int]] _Level = Union[int, str] _FormatStyle = Literal["%", "{", "$"] +_LoggerType = TypeVar("_LoggerType", bound=Logger) raiseExceptions: bool logThreads: bool @@ -59,7 +60,7 @@ class Logger(Filterer): def setLevel(self, level: _Level) -> None: ... def isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... - def getChild(self, suffix: str) -> Logger: ... + def getChild(self: _LoggerType, suffix: str) -> _LoggerType: ... if sys.version_info >= (3, 8): def debug( self, From 31db5fd790f725d19b457f7a6c3dd998c8e36514 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Thu, 16 Dec 2021 13:24:53 +0100 Subject: [PATCH 2/4] Update stdlib/logging/__init__.pyi Co-authored-by: Akuli --- stdlib/logging/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 88ce60b79e71..1a5617b8016b 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -60,7 +60,7 @@ class Logger(Filterer): def setLevel(self, level: _Level) -> None: ... def isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... - def getChild(self: _LoggerType, suffix: str) -> _LoggerType: ... + def getChild(self: Self, suffix: str) -> Self: ... if sys.version_info >= (3, 8): def debug( self, From 97341420d17d44f8dda1c7aa89554d34baaf52ec Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Thu, 16 Dec 2021 13:27:30 +0100 Subject: [PATCH 3/4] added Self import --- stdlib/logging/__init__.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 1a5617b8016b..7823799a5b8b 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -1,6 +1,6 @@ import sys import threading -from _typeshed import StrPath, SupportsWrite +from _typeshed import Self, StrPath, SupportsWrite from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence from io import TextIOWrapper from string import Template @@ -15,7 +15,6 @@ _ArgsType = Union[Tuple[object, ...], Mapping[str, object]] _FilterType = Union[Filter, Callable[[LogRecord], int]] _Level = Union[int, str] _FormatStyle = Literal["%", "{", "$"] -_LoggerType = TypeVar("_LoggerType", bound=Logger) raiseExceptions: bool logThreads: bool From 1e062e3ecf7da3421725c24c1c1508601fff799a Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Thu, 16 Dec 2021 16:29:57 +0100 Subject: [PATCH 4/4] Update stdlib/logging/__init__.pyi Co-authored-by: Alex Waygood --- stdlib/logging/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 7823799a5b8b..2af80d645e12 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -59,7 +59,7 @@ class Logger(Filterer): def setLevel(self, level: _Level) -> None: ... def isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... - def getChild(self: Self, suffix: str) -> Self: ... + def getChild(self: Self, suffix: str) -> Self: ... # see python/typing#980 if sys.version_info >= (3, 8): def debug( self,