[Python-checkins] bpo-41831: Restore str implementation of __str__ in tkinter.EventType (GH-22355)

Serhiy Storchaka webhook-mailer at python.org
Fri Oct 9 15:57:43 EDT 2020


https://github.com/python/cpython/commit/eb38c6b7aa35d3003ec0958533421902d19ce408
commit: eb38c6b7aa35d3003ec0958533421902d19ce408
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-10-09T22:57:34+03:00
summary:

bpo-41831: Restore str implementation of __str__ in tkinter.EventType (GH-22355)

files:
A Misc/NEWS.d/next/Library/2020-09-22-11-07-50.bpo-41831.k-Eop_.rst
M Lib/tkinter/__init__.py

diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index 3919397d3cead..3bfeb7a017903 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -185,8 +185,7 @@ class EventType(enum.StrEnum):
     Deactivate = '37'
     MouseWheel = '38'
 
-    def __str__(self):
-        return self.name
+    __str__ = str.__str__
 
 
 class Event:
@@ -266,7 +265,7 @@ def __repr__(self):
                 'num', 'delta', 'focus',
                 'x', 'y', 'width', 'height')
         return '<%s event%s>' % (
-            self.type,
+            getattr(self.type, 'name', self.type),
             ''.join(' %s=%s' % (k, attrs[k]) for k in keys if k in attrs)
         )
 
diff --git a/Misc/NEWS.d/next/Library/2020-09-22-11-07-50.bpo-41831.k-Eop_.rst b/Misc/NEWS.d/next/Library/2020-09-22-11-07-50.bpo-41831.k-Eop_.rst
new file mode 100644
index 0000000000000..84a3f5253a060
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-09-22-11-07-50.bpo-41831.k-Eop_.rst
@@ -0,0 +1,3 @@
+``str()`` for the ``type`` attribute of the ``tkinter.Event`` object always
+returns now the numeric code returned by Tk instead of the name of the event
+type.



More information about the Python-checkins mailing list