Skip to content

Commit 2768673

Browse files
committed
Fix compare with None
1 parent cedb0c9 commit 2768673

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,11 @@
119119
- Python 3.10 support
120120
- pytest
121121
- black code style
122+
123+
### 2.3
124+
125+
2022-09-01
126+
127+
### Fix
128+
129+
- Fix compare with None

cstruct/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
__author__ = 'Andrea Bonomi <andrea.bonomi@gmail.com>'
2828
__license__ = 'MIT'
29-
__version__ = '2.2'
29+
__version__ = '2.3'
3030
__date__ = '15 August 2013'
3131

3232
import struct

cstruct/abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def size(self) -> int:
141141
return self.__size__
142142

143143
def __eq__(self, other: Any) -> bool:
144-
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
144+
return other is not None and isinstance(other, self.__class__) and self.__dict__ == other.__dict__
145145

146146
def __ne__(self, other: Any) -> bool:
147147
return not self.__eq__(other)

tests/test_cstruct.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,9 @@ def test_nested():
246246
assert flat.endAddrCylSec == nested.end.addrCylSec
247247
assert flat.startLBA == nested.startLBA
248248
assert flat.endLBA == nested.endLBA
249+
250+
251+
def test_null_compare():
252+
c = Dummy()
253+
assert c is not None
254+
assert c != None

tests/test_memcstruct.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,9 @@ def test_nested():
243243
assert flat.endAddrCylSec == nested.end.addrCylSec
244244
assert flat.startLBA == nested.startLBA
245245
assert flat.endLBA == nested.endLBA
246+
247+
248+
def test_null_compare():
249+
c = Dummy()
250+
assert c is not None
251+
assert c != None

0 commit comments

Comments
 (0)