Skip to content

Commit e037901

Browse files
committed
Python 3 preparation: use __bool__ instead of __nonzero__.
Tool-assisted patch. __nonzero__ = __bool__ included for Python 2 compatibility.
1 parent cffee93 commit e037901

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

roundup/cgi/templating.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,10 @@ def __cmp__(self, other):
13431343
return cmp(self._value, other._value)
13441344
return cmp(self._value, other)
13451345

1346-
def __nonzero__(self):
1346+
def __bool__(self):
13471347
return not not self._value
1348+
# Python 2 compatibility:
1349+
__nonzero__ = __bool__
13481350

13491351
def isset(self):
13501352
"""Is my _value not None?"""
@@ -3224,7 +3226,9 @@ def __getattr__(self, name):
32243226
return getattr(self, name)
32253227

32263228
def __getitem__(self, key): return self
3227-
def __nonzero__(self): return 0
3229+
def __bool__(self): return 0
3230+
# Python 2 compatibility:
3231+
__nonzero__ = __bool__
32283232
def __str__(self): return '[%s]'%self.__description
32293233
def __repr__(self): return '<MissingValue 0x%x "%s">'%(id(self),
32303234
self.__description)

test/mocknull.py

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

1818
def __getitem__(self, key): return self
19-
def __nonzero__(self): return 0
19+
def __bool__(self): return 0
20+
# Python 2 compatibility:
21+
__nonzero__ = __bool__
2022
def __str__(self): return ''
2123
def __repr__(self): return '<MockNull 0x%x>'%id(self)
2224
def gettext(self, str): return str

0 commit comments

Comments
 (0)