From 20276ca7cfa4e843c3cd3dd1e8c7bdb0437e887e Mon Sep 17 00:00:00 2001 From: YodaPY Date: Mon, 26 Aug 2024 19:33:30 +0200 Subject: [PATCH 1/5] Make tkinter.Event subscriptable --- Lib/test/test_genericalias.py | 6 +++++- Lib/tkinter/__init__.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index 04122fbdd0ae80..bd9f7f6063abb9 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -57,6 +57,10 @@ from weakref import WeakSet, ReferenceType, ref import typing from typing import Unpack +try: + from tkinter import Event # tkinter is not always available +except ImportError: + Event = None from typing import TypeVar T = TypeVar('T') @@ -133,7 +137,7 @@ class BaseTest(unittest.TestCase): Future, _WorkItem, Morsel, DictReader, DictWriter, - array] + array, Event] if ctypes is not None: generic_types.extend((ctypes.Array, ctypes.LibraryLoader)) if ValueProxy is not None: diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 2e5affb15e3f61..ba962817e62e3c 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -294,6 +294,8 @@ def __repr__(self): getattr(self.type, 'name', self.type), ''.join(' %s=%s' % (k, attrs[k]) for k in keys if k in attrs) ) + + __class_getitem__ = classmethod(types.GenericAlias) _support_default_root = True From 8058df2076902a2602fd60fcb1a6e428d354f965 Mon Sep 17 00:00:00 2001 From: Yoda <64033043+yowoda@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:21:20 +0200 Subject: [PATCH 2/5] fix formatting Co-authored-by: Kirill Podoprigora --- Lib/tkinter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index ba962817e62e3c..dd7b3e138f4236 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -294,7 +294,7 @@ def __repr__(self): getattr(self.type, 'name', self.type), ''.join(' %s=%s' % (k, attrs[k]) for k in keys if k in attrs) ) - + __class_getitem__ = classmethod(types.GenericAlias) From 1fdf65d8f6965cd9852d705d6c3249a8b5a0210e Mon Sep 17 00:00:00 2001 From: YodaPY Date: Tue, 27 Aug 2024 12:26:27 +0200 Subject: [PATCH 3/5] Fix test --- Lib/test/test_genericalias.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index bd9f7f6063abb9..d7a9681c4c21e4 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -58,7 +58,7 @@ import typing from typing import Unpack try: - from tkinter import Event # tkinter is not always available + from tkinter import Event except ImportError: Event = None @@ -143,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: From 42dbcc3f4775079916acd4ada8febdd3833a3a4c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:30:38 +0000 Subject: [PATCH 4/5] =?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/2024-08-27-10-30-37.gh-issue-123341.5e-fjt.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-08-27-10-30-37.gh-issue-123341.5e-fjt.rst 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 index 00000000000000..f60e29020b3cf1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-08-27-10-30-37.gh-issue-123341.5e-fjt.rst @@ -0,0 +1 @@ +Add :meth:`~object.__class_getitem__` to :class:`tkinter.Event` for type subscript support at runtime. Patch by Adonis Rakateli. From 7bb6feeacae0e7298c6ae155e1b5bdaab82b52d7 Mon Sep 17 00:00:00 2001 From: YodaPY Date: Wed, 28 Aug 2024 11:20:31 +0200 Subject: [PATCH 5/5] fix docs failing --- .../next/Library/2024-08-27-10-30-37.gh-issue-123341.5e-fjt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index f60e29020b3cf1..61561eeb807023 100644 --- 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 @@ -1 +1 @@ -Add :meth:`~object.__class_getitem__` to :class:`tkinter.Event` for type subscript support at runtime. Patch by Adonis Rakateli. +Add :meth:`~object.__class_getitem__` to :class:`!tkinter.Event` for type subscript support at runtime. Patch by Adonis Rakateli.