File tree 2 files changed +11
-2
lines changed
2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -907,11 +907,18 @@ def __hash__(self):
907
907
return hash (self ._included ) ^ hash (self ._excluded )
908
908
909
909
def __len__ (self ):
910
- if self ._included :
910
+ if self ._included is not None :
911
911
return len (self ._included )
912
912
raise NotImplementedError ('complemented sets have undefined length' )
913
913
914
914
def __iter__ (self ):
915
- if self ._included :
915
+ if self ._included is not None :
916
916
return iter (self ._included )
917
917
raise NotImplementedError ('complemented sets have undefined contents' )
918
+
919
+ def __bool__ (self ):
920
+ if self ._included is not None :
921
+ return bool (self ._included )
922
+ return True
923
+
924
+ __nonzero__ = __bool__ # py2 compat
Original file line number Diff line number Diff line change @@ -117,6 +117,8 @@ def test_complement_set():
117
117
assert (cab ^ cbc | set ('b' )) == (sab | sbc )
118
118
everything = complement (frozenset ())
119
119
assert everything in everything # https://en.wikipedia.org/wiki/Russell%27s_paradox
120
+ assert bool (cab )
121
+ assert not complement (u )
120
122
# destructive testing
121
123
cab ^= sab
122
124
cab ^= sab
You can’t perform that action at this time.
0 commit comments