Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285. Everything described in the PEP is here, and there is even
some documentation. I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison. I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.
Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 9aa5948..9ee7a39 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -167,34 +167,34 @@
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@')
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2)
-test('startswith', u'hello', 1, u'he')
-test('startswith', u'hello', 1, u'hello')
-test('startswith', u'hello', 0, u'hello world')
-test('startswith', u'hello', 1, u'')
-test('startswith', u'hello', 0, u'ello')
-test('startswith', u'hello', 1, u'ello', 1)
-test('startswith', u'hello', 1, u'o', 4)
-test('startswith', u'hello', 0, u'o', 5)
-test('startswith', u'hello', 1, u'', 5)
-test('startswith', u'hello', 0, u'lo', 6)
-test('startswith', u'helloworld', 1, u'lowo', 3)
-test('startswith', u'helloworld', 1, u'lowo', 3, 7)
-test('startswith', u'helloworld', 0, u'lowo', 3, 6)
+test('startswith', u'hello', True, u'he')
+test('startswith', u'hello', True, u'hello')
+test('startswith', u'hello', False, u'hello world')
+test('startswith', u'hello', True, u'')
+test('startswith', u'hello', False, u'ello')
+test('startswith', u'hello', True, u'ello', 1)
+test('startswith', u'hello', True, u'o', 4)
+test('startswith', u'hello', False, u'o', 5)
+test('startswith', u'hello', True, u'', 5)
+test('startswith', u'hello', False, u'lo', 6)
+test('startswith', u'helloworld', True, u'lowo', 3)
+test('startswith', u'helloworld', True, u'lowo', 3, 7)
+test('startswith', u'helloworld', False, u'lowo', 3, 6)
-test('endswith', u'hello', 1, u'lo')
-test('endswith', u'hello', 0, u'he')
-test('endswith', u'hello', 1, u'')
-test('endswith', u'hello', 0, u'hello world')
-test('endswith', u'helloworld', 0, u'worl')
-test('endswith', u'helloworld', 1, u'worl', 3, 9)
-test('endswith', u'helloworld', 1, u'world', 3, 12)
-test('endswith', u'helloworld', 1, u'lowo', 1, 7)
-test('endswith', u'helloworld', 1, u'lowo', 2, 7)
-test('endswith', u'helloworld', 1, u'lowo', 3, 7)
-test('endswith', u'helloworld', 0, u'lowo', 4, 7)
-test('endswith', u'helloworld', 0, u'lowo', 3, 8)
-test('endswith', u'ab', 0, u'ab', 0, 1)
-test('endswith', u'ab', 0, u'ab', 0, 0)
+test('endswith', u'hello', True, u'lo')
+test('endswith', u'hello', False, u'he')
+test('endswith', u'hello', True, u'')
+test('endswith', u'hello', False, u'hello world')
+test('endswith', u'helloworld', False, u'worl')
+test('endswith', u'helloworld', True, u'worl', 3, 9)
+test('endswith', u'helloworld', True, u'world', 3, 12)
+test('endswith', u'helloworld', True, u'lowo', 1, 7)
+test('endswith', u'helloworld', True, u'lowo', 2, 7)
+test('endswith', u'helloworld', True, u'lowo', 3, 7)
+test('endswith', u'helloworld', False, u'lowo', 4, 7)
+test('endswith', u'helloworld', False, u'lowo', 3, 8)
+test('endswith', u'ab', False, u'ab', 0, 1)
+test('endswith', u'ab', False, u'ab', 0, 0)
test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi')
test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8)
@@ -286,50 +286,50 @@
test('rjust', u'abc', u'abc', 2)
test('center', u'abc', u'abc', 2)
-test('islower', u'a', 1)
-test('islower', u'A', 0)
-test('islower', u'\n', 0)
-test('islower', u'\u1FFc', 0)
-test('islower', u'abc', 1)
-test('islower', u'aBc', 0)
-test('islower', u'abc\n', 1)
+test('islower', u'a', True)
+test('islower', u'A', False)
+test('islower', u'\n', False)
+test('islower', u'\u1FFc', False)
+test('islower', u'abc', True)
+test('islower', u'aBc', False)
+test('islower', u'abc\n', True)
-test('isupper', u'a', 0)
-test('isupper', u'A', 1)
-test('isupper', u'\n', 0)
+test('isupper', u'a', False)
+test('isupper', u'A', True)
+test('isupper', u'\n', False)
if sys.platform[:4] != 'java':
- test('isupper', u'\u1FFc', 0)
-test('isupper', u'ABC', 1)
-test('isupper', u'AbC', 0)
-test('isupper', u'ABC\n', 1)
+ test('isupper', u'\u1FFc', False)
+test('isupper', u'ABC', True)
+test('isupper', u'AbC', False)
+test('isupper', u'ABC\n', True)
-test('istitle', u'a', 0)
-test('istitle', u'A', 1)
-test('istitle', u'\n', 0)
-test('istitle', u'\u1FFc', 1)
-test('istitle', u'A Titlecased Line', 1)
-test('istitle', u'A\nTitlecased Line', 1)
-test('istitle', u'A Titlecased, Line', 1)
-test('istitle', u'Greek \u1FFcitlecases ...', 1)
-test('istitle', u'Not a capitalized String', 0)
-test('istitle', u'Not\ta Titlecase String', 0)
-test('istitle', u'Not--a Titlecase String', 0)
+test('istitle', u'a', False)
+test('istitle', u'A', True)
+test('istitle', u'\n', False)
+test('istitle', u'\u1FFc', True)
+test('istitle', u'A Titlecased Line', True)
+test('istitle', u'A\nTitlecased Line', True)
+test('istitle', u'A Titlecased, Line', True)
+test('istitle', u'Greek \u1FFcitlecases ...', True)
+test('istitle', u'Not a capitalized String', False)
+test('istitle', u'Not\ta Titlecase String', False)
+test('istitle', u'Not--a Titlecase String', False)
-test('isalpha', u'a', 1)
-test('isalpha', u'A', 1)
-test('isalpha', u'\n', 0)
-test('isalpha', u'\u1FFc', 1)
-test('isalpha', u'abc', 1)
-test('isalpha', u'aBc123', 0)
-test('isalpha', u'abc\n', 0)
+test('isalpha', u'a', True)
+test('isalpha', u'A', True)
+test('isalpha', u'\n', False)
+test('isalpha', u'\u1FFc', True)
+test('isalpha', u'abc', True)
+test('isalpha', u'aBc123', False)
+test('isalpha', u'abc\n', False)
-test('isalnum', u'a', 1)
-test('isalnum', u'A', 1)
-test('isalnum', u'\n', 0)
-test('isalnum', u'123abc456', 1)
-test('isalnum', u'a1b3c', 1)
-test('isalnum', u'aBc000 ', 0)
-test('isalnum', u'abc\n', 0)
+test('isalnum', u'a', True)
+test('isalnum', u'A', True)
+test('isalnum', u'\n', False)
+test('isalnum', u'123abc456', True)
+test('isalnum', u'a1b3c', True)
+test('isalnum', u'aBc000 ', False)
+test('isalnum', u'abc\n', False)
test('splitlines', u"abc\ndef\n\rghi", [u'abc', u'def', u'', u'ghi'])
test('splitlines', u"abc\ndef\n\r\nghi", [u'abc', u'def', u'', u'ghi'])
@@ -337,7 +337,7 @@
test('splitlines', u"abc\ndef\r\nghi\n", [u'abc', u'def', u'ghi'])
test('splitlines', u"abc\ndef\r\nghi\n\r", [u'abc', u'def', u'ghi', u''])
test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'', u'abc', u'def', u'ghi', u''])
-test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'\n', u'abc\n', u'def\r\n', u'ghi\n', u'\r'], 1)
+test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'\n', u'abc\n', u'def\r\n', u'ghi\n', u'\r'], True)
test('translate', u"abababc", u'bbbc', {ord('a'):None})
test('translate', u"abababc", u'iiic', {ord('a'):None, ord('b'):ord('i')})