From b65218222e5b7c9b3aecd57260928a8aca6ab5ba Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 1 May 2022 18:42:47 +0100 Subject: [PATCH 1/4] Add the methods --- Lib/logging/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index d6315b047334ec..432fefcb5b3141 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -25,6 +25,7 @@ import sys, os, time, io, re, traceback, warnings, weakref, collections.abc +from types import GenericAlias from string import Template from string import Formatter as StrFormatter @@ -1145,6 +1146,8 @@ def __repr__(self): name += ' ' return '<%s %s(%s)>' % (self.__class__.__name__, name, level) + __class_getitem__ = classmethod(GenericAlias) + class FileHandler(StreamHandler): """ @@ -1939,6 +1942,8 @@ def __repr__(self): level = getLevelName(logger.getEffectiveLevel()) return '<%s %s (%s)>' % (self.__class__.__name__, logger.name, level) + __class_getitem__ = classmethod(GenericAlias) + root = RootLogger(WARNING) Logger.root = root Logger.manager = Manager(Logger.root) From e7ee8a44cda31385e2f12dac501912d9f624c7af Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 1 May 2022 18:49:41 +0100 Subject: [PATCH 2/4] Add tests --- Lib/test/test_genericalias.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index bf96ba065fbb04..635ac0f7a85d7d 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -14,6 +14,7 @@ from dataclasses import Field from functools import partial, partialmethod, cached_property from graphlib import TopologicalSorter +from logging import LoggerAdapter, StreamHandler from mailbox import Mailbox, _PartialFile try: import ctypes @@ -113,6 +114,7 @@ class BaseTest(unittest.TestCase): MappingProxyType, AsyncGeneratorType, DirEntry, chain, + LoggerAdapter, StreamHandler, TemporaryDirectory, SpooledTemporaryFile, Queue, SimpleQueue, _AssertRaisesContext, From 5382db461e9e251d2dbc92fd3096c15610bef193 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 1 May 2022 21:45:42 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst diff --git a/Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst b/Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst new file mode 100644 index 00000000000000..73ac44f02b84c9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst @@ -0,0 +1,2 @@ +Add :meth:`~object.__class_getitem__` to :class:`logging.LoggerAdapter` and +:class:`logging.StreamHandler`. Patch by Alex Waygood. From 2274bbe872ef8a2bd03e2edc9204b69f36311690 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 2 May 2022 13:04:37 +0100 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst --- .../next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst b/Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst index 73ac44f02b84c9..e4d62d221d8a07 100644 --- a/Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst +++ b/Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst @@ -1,2 +1,3 @@ Add :meth:`~object.__class_getitem__` to :class:`logging.LoggerAdapter` and -:class:`logging.StreamHandler`. Patch by Alex Waygood. +:class:`logging.StreamHandler`, allowing them to be parameterized at runtime. +Patch by Alex Waygood.