Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d61d077

Browse files
committed
#1730136: Fix comparison between a tk Font object and an object of a different type.
1 parent 19ec67a commit d61d077

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lib/tkinter/font.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __str__(self):
9797
return self.name
9898

9999
def __eq__(self, other):
100-
return self.name == other.name and isinstance(other, Font)
100+
return isinstance(other, Font) and self.name == other.name
101101

102102
def __getitem__(self, key):
103103
return self.cget(key)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import tkinter
3+
from tkinter import font
4+
from test.support import requires, run_unittest
5+
6+
requires('gui')
7+
8+
class FontTest(unittest.TestCase):
9+
def test_font_eq(self):
10+
font1 = font.nametofont("system")
11+
font2 = font.nametofont("system")
12+
self.assertIsNot(font1, font2)
13+
self.assertEqual(font1, font2)
14+
self.assertNotEqual(font1, font1.copy())
15+
self.assertNotEqual(font1, 0)
16+
17+
tests_gui = (FontTest, )
18+
19+
if __name__ == "__main__":
20+
run_unittest(*tests_gui)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Core and Builtins
5252
Library
5353
-------
5454

55+
- Issue #1730136: Fix the comparison between a tk.font.Font and an object of
56+
another kind.
57+
5558
- Issue #9441: logging has better coverage for rotating file handlers.
5659

5760
- Issue #9865: collections.OrderedDict now has a __sizeof__ method.

0 commit comments

Comments
 (0)