Skip to content

bpo-41876: Overload __repr__ for tkinter Font objects #22450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/tkinter/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def __init__(self, root=None, font=None, name=None, exists=False,
def __str__(self):
return self.name

def __repr__(self):
return f"<{self.__class__.__module__}.{self.__class__.__qualname__} object {self.name!r}>"

def __eq__(self, other):
if not isinstance(other, Font):
return NotImplemented
Expand Down
4 changes: 4 additions & 0 deletions Lib/tkinter/test/test_tkinter/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def test_names(self):
self.assertIsInstance(name, str)
self.assertTrue(name)
self.assertIn(fontname, names)

def test_repr(self):
assert repr(self.font) == f'<{self.font.__class__.__module__}.{self.__class__.__qualname__} object {fontname!r}>'


tests_gui = (FontTest, )

Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ Zero Piraeus
Antoine Pitrou
Jean-François Piéronne
Oleg Plakhotnyuk
Anatoliy Platonov
Marcel Plch
Remi Pointel
Jon Poler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Change in :class:`tkinter.font.Font`, now representation of font object contains
font name instead of object address.