diff --git a/PIL/Image.py b/PIL/Image.py index 787e60270..ea8cc6155 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -573,6 +573,8 @@ class Image: return file def __eq__(self, other): + if self.__class__.__name__ != other.__class__.__name__: + return False a = (self.mode == other.mode) b = (self.size == other.size) c = (self.getpalette() == other.getpalette()) diff --git a/Tests/test_image.py b/Tests/test_image.py index ec82eb419..e41447e42 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -44,6 +44,17 @@ class TestImage(PillowTestCase): file = self.tempfile("temp.ppm") im._dump(file) + def test_comparison_with_other_type(self): + # Arrange + item = Image.new('RGB', (25, 25), '#000') + num = 12 + + # Act/Assert + # Shouldn't cause AttributeError (#774) + self.assertFalse(item is None) + self.assertFalse(item == None) + self.assertFalse(item == num) + if __name__ == '__main__': unittest.main()