From cdbc2d57bc2f4203557bba109f77d539ad2a82b0 Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Tue, 7 Jan 2025 01:20:33 +0800 Subject: [PATCH 1/6] feat: Add decorator `functools.lru_cache` to method `tkinter.Misc.winfo_rgb` --- Lib/tkinter/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index d494c0c9687cd1..656d6f7c75b295 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -34,6 +34,7 @@ import enum import sys import types +import functools import _tkinter # If this fails your Python may not be configured for Tk TclError = _tkinter.TclError @@ -1314,6 +1315,7 @@ def winfo_reqwidth(self): return self.tk.getint( self.tk.call('winfo', 'reqwidth', self._w)) + @functools.lru_cache def winfo_rgb(self, color): """Return a tuple of integer RGB values in range(65536) for color in this widget.""" return self._getints( From 7eea4716980f277afcfaca88c978eeb1b5eb82ab Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 05:25:59 +0000 Subject: [PATCH 2/6] =?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/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst diff --git a/Misc/NEWS.d/next/Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst b/Misc/NEWS.d/next/Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst new file mode 100644 index 00000000000000..e6c0cd6545a674 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst @@ -0,0 +1 @@ +Add decorator ``functools.lru_cache`` to the :mod:`tkinter` method :meth:`!winfo_rgb`. From 004cd11a41455f4d27a0fee8adab19c37653541b Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Tue, 7 Jan 2025 13:30:54 +0800 Subject: [PATCH 3/6] style: Improve the changelog --- .../Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst b/Misc/NEWS.d/next/Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst index e6c0cd6545a674..15f6cdca13b8b2 100644 --- a/Misc/NEWS.d/next/Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst +++ b/Misc/NEWS.d/next/Library/2025-01-07-05-25-57.gh-issue-128576.qzDkju.rst @@ -1 +1,2 @@ -Add decorator ``functools.lru_cache`` to the :mod:`tkinter` method :meth:`!winfo_rgb`. +Add decorator :func:`functools.lru_cache` to the :mod:`tkinter` method +:meth:`!winfo_rgb`. From 27136d738f08d0b5a914eae944a4424a21e8dcaf Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Tue, 7 Jan 2025 18:47:01 +0800 Subject: [PATCH 4/6] style: Sort the import --- 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 656d6f7c75b295..d3547bafc9ee08 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -32,9 +32,9 @@ import collections import enum +import functools import sys import types -import functools import _tkinter # If this fails your Python may not be configured for Tk TclError = _tkinter.TclError From acce9afc6fef840c1817d6b9813ba9fa2069774a Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Tue, 7 Jan 2025 19:21:29 +0800 Subject: [PATCH 5/6] feat: Add magic methods `__eq__` and `__hash__` to class `tkinter.Misc` --- Lib/tkinter/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index d3547bafc9ee08..cc297c0099eadc 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1850,6 +1850,12 @@ def __repr__(self): return '<%s.%s object %s>' % ( self.__class__.__module__, self.__class__.__qualname__, self._w) + def __eq__(self, other): + return self._w == other._w + + def __hash__(self): + return hash(self._w) + # Pack methods that apply to the master _noarg_ = ['_noarg_'] From da6a174de5a902c74f10b37e55ec32c3fa3ec44b Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Tue, 7 Jan 2025 19:36:39 +0800 Subject: [PATCH 6/6] fix: Fix the magic method `__eq__` --- Lib/tkinter/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index cc297c0099eadc..401ba092deb421 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1851,7 +1851,10 @@ def __repr__(self): self.__class__.__module__, self.__class__.__qualname__, self._w) def __eq__(self, other): - return self._w == other._w + if isinstance(other, Misc): + return self._w == other._w + + return False def __hash__(self): return hash(self._w)