diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-08-08 05:42:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-08 05:42:54 (GMT) |
commit | 662db125cddbca1db68116c547c290eb3943d98e (patch) | |
tree | 06151487dbe4493ef173dd8cc378f4b6cf5c0e4a /Lib/tkinter | |
parent | 4c69be22df3852f17873a74d015528d9a8ae92d6 (diff) | |
download | cpython-662db125cddbca1db68116c547c290eb3943d98e.zip cpython-662db125cddbca1db68116c547c290eb3943d98e.tar.gz cpython-662db125cddbca1db68116c547c290eb3943d98e.tar.bz2 |
bpo-37685: Fixed __eq__, __lt__ etc implementations in some classes. (GH-14952)
They now return NotImplemented for unsupported type of the other operand.
Diffstat (limited to 'Lib/tkinter')
-rw-r--r-- | Lib/tkinter/__init__.py | 2 | ||||
-rw-r--r-- | Lib/tkinter/font.py | 4 | ||||
-rw-r--r-- | Lib/tkinter/test/test_tkinter/test_font.py | 3 | ||||
-rw-r--r-- | Lib/tkinter/test/test_tkinter/test_variables.py | 13 |
4 files changed, 17 insertions, 5 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 9626a27..9258484 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -484,6 +484,8 @@ class Variable: Note: if the Variable's master matters to behavior also compare self._master == other._master """ + if not isinstance(other, Variable): + return NotImplemented return self.__class__.__name__ == other.__class__.__name__ \ and self._name == other._name diff --git a/Lib/tkinter/font.py b/Lib/tkinter/font.py index eeff454..15ad7ab 100644 --- a/Lib/tkinter/font.py +++ b/Lib/tkinter/font.py @@ -101,7 +101,9 @@ class Font: return self.name def __eq__(self, other): - return isinstance(other, Font) and self.name == other.name + if not isinstance(other, Font): + return NotImplemented + return self.name == other.name def __getitem__(self, key): return self.cget(key) diff --git a/Lib/tkinter/test/test_tkinter/test_font.py b/Lib/tkinter/test/test_tkinter/test_font.py index 97cd87c..a021ea3 100644 --- a/Lib/tkinter/test/test_tkinter/test_font.py +++ b/Lib/tkinter/test/test_tkinter/test_font.py @@ -1,7 +1,7 @@ import unittest import tkinter from tkinter import font -from test.support import requires, run_unittest, gc_collect +from test.support import requires, run_unittest, gc_collect, ALWAYS_EQ from tkinter.test.support import AbstractTkTest requires('gui') @@ -70,6 +70,7 @@ class FontTest(AbstractTkTest, unittest.TestCase): self.assertEqual(font1, font2) self.assertNotEqual(font1, font1.copy()) self.assertNotEqual(font1, 0) + self.assertEqual(font1, ALWAYS_EQ) def test_measure(self): self.assertIsInstance(self.font.measure('abc'), int) diff --git a/Lib/tkinter/test/test_tkinter/test_variables.py b/Lib/tkinter/test/test_tkinter/test_variables.py index 2eb1e12..08b7ded 100644 --- a/Lib/tkinter/test/test_tkinter/test_variables.py +++ b/Lib/tkinter/test/test_tkinter/test_variables.py @@ -2,6 +2,7 @@ import unittest import gc from tkinter import (Variable, StringVar, IntVar, DoubleVar, BooleanVar, Tcl, TclError) +from test.support import ALWAYS_EQ class Var(Variable): @@ -59,11 +60,17 @@ class TestVariable(TestBase): # values doesn't matter, only class and name are checked v1 = Variable(self.root, name="abc") v2 = Variable(self.root, name="abc") + self.assertIsNot(v1, v2) self.assertEqual(v1, v2) - v3 = Variable(self.root, name="abc") - v4 = StringVar(self.root, name="abc") - self.assertNotEqual(v3, v4) + v3 = StringVar(self.root, name="abc") + self.assertNotEqual(v1, v3) + + V = type('Variable', (), {}) + self.assertNotEqual(v1, V()) + + self.assertNotEqual(v1, object()) + self.assertEqual(v1, ALWAYS_EQ) def test_invalid_name(self): with self.assertRaises(TypeError): |