Skip to content

Commit 98aa9ea

Browse files
committed
fix MissingValue / MockNull to return False on __bool__ and add a
__contains__ to support 'in' operator correctly
1 parent b37e1f6 commit 98aa9ea

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

roundup/cgi/templating.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3240,9 +3240,10 @@ def __getattr__(self, name):
32403240
return getattr(self, name)
32413241

32423242
def __getitem__(self, key): return self
3243-
def __bool__(self): return 0
3243+
def __bool__(self): return False
32443244
# Python 2 compatibility:
32453245
__nonzero__ = __bool__
3246+
def __contains__(self, key): return False
32463247
def __str__(self): return '[%s]'%self.__description
32473248
def __repr__(self): return '<MissingValue 0x%x "%s">'%(id(self),
32483249
self.__description)

test/mocknull.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ def __getattr__(self, name):
1616
return getattr(self, name)
1717

1818
def __getitem__(self, key): return self
19-
def __bool__(self): return 0
19+
def __bool__(self): return False
2020
# Python 2 compatibility:
2121
__nonzero__ = __bool__
22+
def __contains__(self, key): return False
2223
def __str__(self): return ''
2324
def __repr__(self): return '<MockNull 0x%x>'%id(self)
2425
def gettext(self, str): return str

0 commit comments

Comments
 (0)