summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorAnatoliy Platonov <31926941+p4m-dev@users.noreply.github.com>2020-10-14 10:02:51 (GMT)
committerGitHub <noreply@github.com>2020-10-14 10:02:51 (GMT)
commitb4d895336a4692c95b4533adcc5c63a489e5e4e4 (patch)
tree0a9cd544bf4082d1db7a3d38c8f2c0f41f4a7ae3 /Lib/tkinter
parent0cafcd3c56c9475913d8d4fd0223c297dbb70ac6 (diff)
downloadcpython-b4d895336a4692c95b4533adcc5c63a489e5e4e4.zip
cpython-b4d895336a4692c95b4533adcc5c63a489e5e4e4.tar.gz
cpython-b4d895336a4692c95b4533adcc5c63a489e5e4e4.tar.bz2
bpo-41876: Overload __repr__ for tkinter Font objects (GH-22450)
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/font.py4
-rw-r--r--Lib/tkinter/test/test_tkinter/test_font.py6
2 files changed, 10 insertions, 0 deletions
diff --git a/Lib/tkinter/font.py b/Lib/tkinter/font.py
index 15ad7ab..a9f79d8 100644
--- a/Lib/tkinter/font.py
+++ b/Lib/tkinter/font.py
@@ -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
diff --git a/Lib/tkinter/test/test_tkinter/test_font.py b/Lib/tkinter/test/test_tkinter/test_font.py
index a021ea3..6d1eea4 100644
--- a/Lib/tkinter/test/test_tkinter/test_font.py
+++ b/Lib/tkinter/test/test_tkinter/test_font.py
@@ -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__":