]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41831: Restore str implementation of __str__ in tkinter.EventType (GH-22355)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 9 Oct 2020 19:57:34 +0000 (22:57 +0300)
committerGitHub <noreply@github.com>
Fri, 9 Oct 2020 19:57:34 +0000 (22:57 +0300)
Lib/tkinter/__init__.py
Misc/NEWS.d/next/Library/2020-09-22-11-07-50.bpo-41831.k-Eop_.rst [new file with mode: 0644]

index 3919397d3cead24fd9ac51f73e7c52cb4a85c1f4..3bfeb7a0179036e95ea43a2495f9c405e5aeef12 100644 (file)
@@ -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 @@ class Event:
                 '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 (file)
index 0000000..84a3f52
--- /dev/null
@@ -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.