bpo-41876: Overload __repr__ for tkinter Font objects (GH-22450)

This commit is contained in:
Anatoliy Platonov 2020-10-14 13:02:51 +03:00 committed by GitHub
parent 0cafcd3c56
commit b4d895336a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 0 deletions

View File

@ -100,6 +100,10 @@ class Font:
def __str__(self): def __str__(self):
return self.name return self.name
def __repr__(self):
return f"<{self.__class__.__module__}.{self.__class__.__qualname__}" \
f" object {self.name!r}>"
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, Font): if not isinstance(other, Font):
return NotImplemented return NotImplemented

View File

@ -101,6 +101,12 @@ class FontTest(AbstractTkTest, unittest.TestCase):
self.assertTrue(name) self.assertTrue(name)
self.assertIn(fontname, names) self.assertIn(fontname, names)
def test_repr(self):
self.assertEqual(
repr(self.font), f'<tkinter.font.Font object {fontname!r}>'
)
tests_gui = (FontTest, ) tests_gui = (FontTest, )
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1353,6 +1353,7 @@ Zero Piraeus
Antoine Pitrou Antoine Pitrou
Jean-François Piéronne Jean-François Piéronne
Oleg Plakhotnyuk Oleg Plakhotnyuk
Anatoliy Platonov
Marcel Plch Marcel Plch
Remi Pointel Remi Pointel
Jon Poler Jon Poler

View File

@ -0,0 +1 @@
Tkinter font class repr uses font name