]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41876: Overload __repr__ for tkinter Font objects (GH-22450)
authorAnatoliy Platonov <31926941+p4m-dev@users.noreply.github.com>
Wed, 14 Oct 2020 10:02:51 +0000 (13:02 +0300)
committerGitHub <noreply@github.com>
Wed, 14 Oct 2020 10:02:51 +0000 (13:02 +0300)
Lib/tkinter/font.py
Lib/tkinter/test/test_tkinter/test_font.py
Misc/ACKS
Misc/NEWS.d/next/Library/2020-09-29-16-23-54.bpo-41876.QicdDU.rst [new file with mode: 0644]

index 15ad7ab4b63a81509590b2135ad867aa295054cc..a9f79d8e456bb7198a89b0eeb8527f4db263c6b7 100644 (file)
@@ -100,6 +100,10 @@ class Font:
     def __str__(self):
         return self.name
 
+    def __repr__(self):
+        return f"<{self.__class__.__module__}.{self.__class__.__qualname__}" \
+               f" object {self.name!r}>"
+
     def __eq__(self, other):
         if not isinstance(other, Font):
             return NotImplemented
index a021ea336807bb8e95571ee12755d7dcb6526f54..6d1eea44b4d2f32c3e6909d4c431d41fe20550d0 100644 (file)
@@ -101,6 +101,12 @@ class FontTest(AbstractTkTest, unittest.TestCase):
             self.assertTrue(name)
         self.assertIn(fontname, names)
 
+    def test_repr(self):
+        self.assertEqual(
+            repr(self.font), f'<tkinter.font.Font object {fontname!r}>'
+        )
+
+
 tests_gui = (FontTest, )
 
 if __name__ == "__main__":
index 660b8ef7504eebc7b4fc56f5b378d2e0d0111487..7f4a9bcbc0f8cdb05cb4e784c5592ae8fcc15352 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1353,6 +1353,7 @@ Zero Piraeus
 Antoine Pitrou
 Jean-François Piéronne
 Oleg Plakhotnyuk
+Anatoliy Platonov
 Marcel Plch
 Remi Pointel
 Jon Poler
diff --git a/Misc/NEWS.d/next/Library/2020-09-29-16-23-54.bpo-41876.QicdDU.rst b/Misc/NEWS.d/next/Library/2020-09-29-16-23-54.bpo-41876.QicdDU.rst
new file mode 100644 (file)
index 0000000..d4f5f0a
--- /dev/null
@@ -0,0 +1 @@
+Tkinter font class repr uses font name
\ No newline at end of file