diff --git a/Lib/functools.py b/Lib/functools.py index 77ec852805c104..ab718d591a4e95 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -923,6 +923,8 @@ def _method(*args, **kwargs): def __isabstractmethod__(self): return getattr(self.func, '__isabstractmethod__', False) + __class_getitem__ = classmethod(GenericAlias) + ################################################################################ ### cached_property() - computed once per instance, cached as attribute diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index 0daaff099a868d..ccd41826debd5a 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -12,7 +12,9 @@ from contextlib import AbstractContextManager, AbstractAsyncContextManager from contextvars import ContextVar, Token from dataclasses import Field -from functools import partial, partialmethod, cached_property +from functools import ( + partial, partialmethod, cached_property, singledispatchmethod +) from mailbox import Mailbox, _PartialFile try: import ctypes @@ -55,7 +57,8 @@ class BaseTest(unittest.TestCase): FileInput, OrderedDict, Counter, UserDict, UserList, Pattern, Match, - partial, partialmethod, cached_property, + partial, partialmethod, + cached_property, singledispatchmethod, AbstractContextManager, AbstractAsyncContextManager, Awaitable, Coroutine, AsyncIterable, AsyncIterator, diff --git a/Misc/NEWS.d/next/Library/2021-11-01-22-40-18.bpo-45684.4mkten.rst b/Misc/NEWS.d/next/Library/2021-11-01-22-40-18.bpo-45684.4mkten.rst new file mode 100644 index 00000000000000..89ee869db426eb --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-11-01-22-40-18.bpo-45684.4mkten.rst @@ -0,0 +1 @@ +Add ``__class_getitem__`` method to ``functools.singledispatchmethod``.