mirror of https://github.com/python/cpython
- bool() called without arguments now returns False rather than
raising an exception. This is consistent with calling the constructors for the other builtin types -- called without argument they all return the false value of that type. (SF patch #724135) Thanks to Alex Martelli.
This commit is contained in:
parent
a26854095b
commit
aa86e35c52
|
@ -137,6 +137,7 @@ veris(bool(-1), True)
|
||||||
veris(bool(0), False)
|
veris(bool(0), False)
|
||||||
veris(bool("hello"), True)
|
veris(bool("hello"), True)
|
||||||
veris(bool(""), False)
|
veris(bool(""), False)
|
||||||
|
veris(bool(), False)
|
||||||
|
|
||||||
veris(hasattr([], "append"), True)
|
veris(hasattr([], "append"), True)
|
||||||
veris(hasattr([], "wobble"), False)
|
veris(hasattr([], "wobble"), False)
|
||||||
|
|
|
@ -86,6 +86,10 @@ if 0 != 0L or 0 != 0.0 or 0L != 0.0: raise TestFailed, 'mixed comparisons'
|
||||||
if 1 != 1L or 1 != 1.0 or 1L != 1.0: raise TestFailed, 'mixed comparisons'
|
if 1 != 1L or 1 != 1.0 or 1L != 1.0: raise TestFailed, 'mixed comparisons'
|
||||||
if -1 != -1L or -1 != -1.0 or -1L != -1.0:
|
if -1 != -1L or -1 != -1.0 or -1L != -1.0:
|
||||||
raise TestFailed, 'int/long/float value not equal'
|
raise TestFailed, 'int/long/float value not equal'
|
||||||
|
# calling built-in types without argument must return 0
|
||||||
|
if int() != 0: raise TestFailed, 'int() does not return 0'
|
||||||
|
if long() != 0L: raise TestFailed, 'long() does not return 0L'
|
||||||
|
if float() != 0.0: raise TestFailed, 'float() does not return 0.0'
|
||||||
if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
|
if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
|
||||||
else: raise TestFailed, 'int() does not round properly'
|
else: raise TestFailed, 'int() does not round properly'
|
||||||
if long(1.9) == 1L == long(1.1) and long(-1.1) == -1L == long(-1.9): pass
|
if long(1.9) == 1L == long(1.1) and long(-1.1) == -1L == long(-1.9): pass
|
||||||
|
@ -214,6 +218,8 @@ if have_unicode:
|
||||||
|
|
||||||
|
|
||||||
print '6.5.2 Tuples'
|
print '6.5.2 Tuples'
|
||||||
|
# calling built-in types without argument must return empty
|
||||||
|
if tuple() != (): raise TestFailed,'tuple() does not return ()'
|
||||||
if len(()) != 0: raise TestFailed, 'len(())'
|
if len(()) != 0: raise TestFailed, 'len(())'
|
||||||
if len((1,)) != 1: raise TestFailed, 'len((1,))'
|
if len((1,)) != 1: raise TestFailed, 'len((1,))'
|
||||||
if len((1,2,3,4,5,6)) != 6: raise TestFailed, 'len((1,2,3,4,5,6))'
|
if len((1,2,3,4,5,6)) != 6: raise TestFailed, 'len((1,2,3,4,5,6))'
|
||||||
|
@ -251,6 +257,8 @@ def f():
|
||||||
vereq(list(tuple(f())), range(1000))
|
vereq(list(tuple(f())), range(1000))
|
||||||
|
|
||||||
print '6.5.3 Lists'
|
print '6.5.3 Lists'
|
||||||
|
# calling built-in types without argument must return empty
|
||||||
|
if list() != []: raise TestFailed,'list() does not return []'
|
||||||
if len([]) != 0: raise TestFailed, 'len([])'
|
if len([]) != 0: raise TestFailed, 'len([])'
|
||||||
if len([1,]) != 1: raise TestFailed, 'len([1,])'
|
if len([1,]) != 1: raise TestFailed, 'len([1,])'
|
||||||
if len([1,2,3,4,5,6]) != 6: raise TestFailed, 'len([1,2,3,4,5,6])'
|
if len([1,2,3,4,5,6]) != 6: raise TestFailed, 'len([1,2,3,4,5,6])'
|
||||||
|
@ -441,6 +449,8 @@ vereq(a, [0, 1, 1, 3, 2, 5, 3, 7, 4, 9])
|
||||||
|
|
||||||
|
|
||||||
print '6.6 Mappings == Dictionaries'
|
print '6.6 Mappings == Dictionaries'
|
||||||
|
# calling built-in types without argument must return empty
|
||||||
|
if dict() != {}: raise TestFailed,'dict() does not return {}'
|
||||||
d = {}
|
d = {}
|
||||||
if d.keys() != []: raise TestFailed, '{}.keys()'
|
if d.keys() != []: raise TestFailed, '{}.keys()'
|
||||||
if d.values() != []: raise TestFailed, '{}.values()'
|
if d.values() != []: raise TestFailed, '{}.values()'
|
||||||
|
|
|
@ -12,6 +12,11 @@ What's New in Python 2.3 beta 1?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- bool() called without arguments now returns False rather than
|
||||||
|
raising an exception. This is consistent with calling the
|
||||||
|
constructors for the other builtin types -- called without argument
|
||||||
|
they all return the false value of that type. (SF patch #724135)
|
||||||
|
|
||||||
- In support of PEP 269 (making the pgen parser generator accessible
|
- In support of PEP 269 (making the pgen parser generator accessible
|
||||||
from Python), some changes to the pgen code structure were made; a
|
from Python), some changes to the pgen code structure were made; a
|
||||||
few files that used to be linked only with pgen are now linked with
|
few files that used to be linked only with pgen are now linked with
|
||||||
|
|
|
@ -51,10 +51,10 @@ static PyObject *
|
||||||
bool_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
bool_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
static char *kwlist[] = {"x", 0};
|
static char *kwlist[] = {"x", 0};
|
||||||
PyObject *x;
|
PyObject *x = Py_False;
|
||||||
long ok;
|
long ok;
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:bool", kwlist, &x))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bool", kwlist, &x))
|
||||||
return NULL;
|
return NULL;
|
||||||
ok = PyObject_IsTrue(x);
|
ok = PyObject_IsTrue(x);
|
||||||
if (ok < 0)
|
if (ok < 0)
|
||||||
|
|
Loading…
Reference in New Issue