diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2022-05-02 15:10:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 15:10:02 (GMT) |
commit | ab616d323dbc473f8d5563b596e882ed3ccdf77b (patch) | |
tree | d5ec3c1d089faafbc0c6828f7e25efe13a0179c0 | |
parent | 031397063e9c22711abfbf90f2617c8785cfc42c (diff) | |
download | cpython-ab616d323dbc473f8d5563b596e882ed3ccdf77b.zip cpython-ab616d323dbc473f8d5563b596e882ed3ccdf77b.tar.gz cpython-ab616d323dbc473f8d5563b596e882ed3ccdf77b.tar.bz2 |
gh-92128: Add `__class_getitem__` to `logging.LoggerAdapter` and `logging.StreamHandler` (#92129)
Closes #92128
-rw-r--r-- | Lib/logging/__init__.py | 5 | ||||
-rw-r--r-- | Lib/test/test_genericalias.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst | 3 |
3 files changed, 10 insertions, 0 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index d6315b0..432fefc 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -25,6 +25,7 @@ To use, simply 'import logging' and log away! 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 @@ class StreamHandler(Handler): name += ' ' return '<%s %s(%s)>' % (self.__class__.__name__, name, level) + __class_getitem__ = classmethod(GenericAlias) + class FileHandler(StreamHandler): """ @@ -1939,6 +1942,8 @@ class LoggerAdapter(object): 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) diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index bf96ba0..635ac0f 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -14,6 +14,7 @@ from contextvars import ContextVar, Token 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, 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 0000000..e4d62d2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-01-21-45-41.gh-issue-92128.Di7VbE.rst @@ -0,0 +1,3 @@ +Add :meth:`~object.__class_getitem__` to :class:`logging.LoggerAdapter` and
+:class:`logging.StreamHandler`, allowing them to be parameterized at runtime.
+Patch by Alex Waygood.
|