]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123341: Support `tkinter.Event` type subcript (#123353)
authorYoda <64033043+yowoda@users.noreply.github.com>
Sun, 1 Sep 2024 11:47:07 +0000 (13:47 +0200)
committerGitHub <noreply@github.com>
Sun, 1 Sep 2024 11:47:07 +0000 (12:47 +0100)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Lib/test/test_genericalias.py
Lib/tkinter/__init__.py
Misc/NEWS.d/next/Library/2024-08-27-10-30-37.gh-issue-123341.5e-fjt.rst [new file with mode: 0644]

index 04122fbdd0ae80be98ced5c623db2c1d8a913d18..12564b423493aab12282598f9ca565b107e0c8ae 100644 (file)
@@ -57,6 +57,10 @@ from queue import Queue, SimpleQueue
 from weakref import WeakSet, ReferenceType, ref
 import typing
 from typing import Unpack
+try:
+    from tkinter import Event
+except ImportError:
+    Event = None
 
 from typing import TypeVar
 T = TypeVar('T')
@@ -139,6 +143,8 @@ class BaseTest(unittest.TestCase):
     if ValueProxy is not None:
         generic_types.extend((ValueProxy, DictProxy, ListProxy, ApplyResult,
                               MPSimpleQueue, MPQueue, MPJoinableQueue))
+    if Event is not None:
+        generic_types.append(Event)
 
     def test_subscriptable(self):
         for t in self.generic_types:
index 2e5affb15e3f6159184a713d9d543124cec1be87..dd7b3e138f4236c970ef3ade819af263e0ae7059 100644 (file)
@@ -295,6 +295,8 @@ class Event:
             ''.join(' %s=%s' % (k, attrs[k]) for k in keys if k in attrs)
         )
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 
 _support_default_root = True
 _default_root = None
diff --git a/Misc/NEWS.d/next/Library/2024-08-27-10-30-37.gh-issue-123341.5e-fjt.rst b/Misc/NEWS.d/next/Library/2024-08-27-10-30-37.gh-issue-123341.5e-fjt.rst
new file mode 100644 (file)
index 0000000..61561ee
--- /dev/null
@@ -0,0 +1 @@
+Add :meth:`~object.__class_getitem__` to :class:`!tkinter.Event` for type subscript support at runtime. Patch by Adonis Rakateli.