diff options
author | Guido van Rossum <guido@python.org> | 2002-04-03 22:41:51 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-04-03 22:41:51 (GMT) |
commit | 77f6a65eb00f005939c6c7c5d6ac0f037a0ce1bd (patch) | |
tree | e92163095e7ae548c36cea459dad87db74a413ef /Objects | |
parent | e9c0358bf45bd6e0fe0b17720b41d20d618e6d9d (diff) | |
download | cpython-77f6a65eb00f005939c6c7c5d6ac0f037a0ce1bd.zip cpython-77f6a65eb00f005939c6c7c5d6ac0f037a0ce1bd.tar.gz cpython-77f6a65eb00f005939c6c7c5d6ac0f037a0ce1bd.tar.bz2 |
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.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/dictobject.c | 2 | ||||
-rw-r--r-- | Objects/fileobject.c | 6 | ||||
-rw-r--r-- | Objects/intobject.c | 12 | ||||
-rw-r--r-- | Objects/object.c | 3 | ||||
-rw-r--r-- | Objects/stringobject.c | 128 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 144 |
6 files changed, 143 insertions, 152 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index f4cf0df..b720ae5 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1429,7 +1429,7 @@ dict_has_key(register dictobject *mp, PyObject *key) return NULL; } ok = (mp->ma_lookup)(mp, key, hash)->me_value != NULL; - return PyInt_FromLong(ok); + return PyBool_FromLong(ok); } static PyObject * diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 3179574..3e0b85e 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -1444,7 +1444,7 @@ static char flush_doc[] = static char close_doc[] = "close() -> None or (perhaps) an integer. Close the file.\n" "\n" -"Sets data attribute .closed to true. A closed file cannot be used for\n" +"Sets data attribute .closed to True. A closed file cannot be used for\n" "further I/O operations. close() may be called more than once without\n" "error. Some kinds of file objects (for example, opened by popen())\n" "may return an exit status upon closing."; @@ -1488,11 +1488,11 @@ static PyMemberDef file_memberlist[] = { static PyObject * get_closed(PyFileObject *f, void *closure) { - return PyInt_FromLong((long)(f->f_fp == 0)); + return PyBool_FromLong((long)(f->f_fp == 0)); } static PyGetSetDef file_getsetlist[] = { - {"closed", (getter)get_closed, NULL, "flag set if the file is closed"}, + {"closed", (getter)get_closed, NULL, "True if the file is closed"}, {0}, }; diff --git a/Objects/intobject.c b/Objects/intobject.c index 6c8bdbe..5886209 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -10,18 +10,6 @@ PyInt_GetMax(void) return LONG_MAX; /* To initialize sys.maxint */ } -/* Standard Booleans */ - -PyIntObject _Py_ZeroStruct = { - PyObject_HEAD_INIT(&PyInt_Type) - 0 -}; - -PyIntObject _Py_TrueStruct = { - PyObject_HEAD_INIT(&PyInt_Type) - 1 -}; - /* Return 1 if exception raised, 0 if caller should retry using longs */ static int err_ovf(char *msg) diff --git a/Objects/object.c b/Objects/object.c index 396f734..6cb5747 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1763,6 +1763,9 @@ _Py_ReadyTypes(void) if (PyType_Ready(&PyType_Type) < 0) Py_FatalError("Can't initialize 'type'"); + if (PyType_Ready(&PyBool_Type) < 0) + Py_FatalError("Can't initialize 'bool'"); + if (PyType_Ready(&PyList_Type) < 0) Py_FatalError("Can't initialize 'list'"); diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 144c5b0..2a63cfe 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -2000,9 +2000,9 @@ string_replace(PyStringObject *self, PyObject *args) static char startswith__doc__[] = -"S.startswith(prefix[, start[, end]]) -> int\n\ +"S.startswith(prefix[, start[, end]]) -> bool\n\ \n\ -Return 1 if S starts with the specified prefix, otherwise return 0. With\n\ +Return True if S starts with the specified prefix, False otherwise. With\n\ optional start, test S beginning at that position. With optional end, stop\n\ comparing S at that position."; @@ -2032,7 +2032,7 @@ string_startswith(PyStringObject *self, PyObject *args) if (rc == -1) return NULL; else - return PyInt_FromLong((long) rc); + return PyBool_FromLong((long) rc); } #endif else if (PyObject_AsCharBuffer(subobj, &prefix, &plen)) @@ -2043,25 +2043,25 @@ string_startswith(PyStringObject *self, PyObject *args) * the empty string. */ if (start < 0 || start+plen > len) - return PyInt_FromLong(0); + return PyBool_FromLong(0); if (!memcmp(str+start, prefix, plen)) { /* did the match end after the specified end? */ if (end < 0) - return PyInt_FromLong(1); + return PyBool_FromLong(1); else if (end - start < plen) - return PyInt_FromLong(0); + return PyBool_FromLong(0); else - return PyInt_FromLong(1); + return PyBool_FromLong(1); } - else return PyInt_FromLong(0); + else return PyBool_FromLong(0); } static char endswith__doc__[] = -"S.endswith(suffix[, start[, end]]) -> int\n\ +"S.endswith(suffix[, start[, end]]) -> bool\n\ \n\ -Return 1 if S ends with the specified suffix, otherwise return 0. With\n\ +Return True if S ends with the specified suffix, False otherwise. With\n\ optional start, test S beginning at that position. With optional end, stop\n\ comparing S at that position."; @@ -2092,21 +2092,21 @@ string_endswith(PyStringObject *self, PyObject *args) if (rc == -1) return NULL; else - return PyInt_FromLong((long) rc); + return PyBool_FromLong((long) rc); } #endif else if (PyObject_AsCharBuffer(subobj, &suffix, &slen)) return NULL; if (start < 0 || start > len || slen > len) - return PyInt_FromLong(0); + return PyBool_FromLong(0); upper = (end >= 0 && end <= len) ? end : len; lower = (upper - slen) > start ? (upper - slen) : start; if (upper-lower >= slen && !memcmp(str+lower, suffix, slen)) - return PyInt_FromLong(1); - else return PyInt_FromLong(0); + return PyBool_FromLong(1); + else return PyBool_FromLong(0); } @@ -2311,10 +2311,10 @@ string_center(PyStringObject *self, PyObject *args) } static char isspace__doc__[] = -"S.isspace() -> int\n" +"S.isspace() -> bool\n" "\n" -"Return 1 if there are only whitespace characters in S,\n" -"0 otherwise."; +"Return True if there are only whitespace characters in S,\n" +"False otherwise."; static PyObject* string_isspace(PyStringObject *self) @@ -2326,26 +2326,26 @@ string_isspace(PyStringObject *self) /* Shortcut for single character strings */ if (PyString_GET_SIZE(self) == 1 && isspace(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyString_GET_SIZE(self); for (; p < e; p++) { if (!isspace(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char isalpha__doc__[] = -"S.isalpha() -> int\n\ +"S.isalpha() -> bool\n\ \n\ -Return 1 if all characters in S are alphabetic\n\ -and there is at least one character in S, 0 otherwise."; +Return True if all characters in S are alphabetic\n\ +and there is at least one character in S, False otherwise."; static PyObject* string_isalpha(PyStringObject *self) @@ -2357,26 +2357,26 @@ string_isalpha(PyStringObject *self) /* Shortcut for single character strings */ if (PyString_GET_SIZE(self) == 1 && isalpha(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyString_GET_SIZE(self); for (; p < e; p++) { if (!isalpha(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char isalnum__doc__[] = -"S.isalnum() -> int\n\ +"S.isalnum() -> bool\n\ \n\ -Return 1 if all characters in S are alphanumeric\n\ -and there is at least one character in S, 0 otherwise."; +Return True if all characters in S are alphanumeric\n\ +and there is at least one character in S, False otherwise."; static PyObject* string_isalnum(PyStringObject *self) @@ -2388,26 +2388,26 @@ string_isalnum(PyStringObject *self) /* Shortcut for single character strings */ if (PyString_GET_SIZE(self) == 1 && isalnum(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyString_GET_SIZE(self); for (; p < e; p++) { if (!isalnum(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char isdigit__doc__[] = -"S.isdigit() -> int\n\ +"S.isdigit() -> bool\n\ \n\ -Return 1 if there are only digit characters in S,\n\ -0 otherwise."; +Return True if there are only digit characters in S,\n\ +False otherwise."; static PyObject* string_isdigit(PyStringObject *self) @@ -2419,26 +2419,26 @@ string_isdigit(PyStringObject *self) /* Shortcut for single character strings */ if (PyString_GET_SIZE(self) == 1 && isdigit(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyString_GET_SIZE(self); for (; p < e; p++) { if (!isdigit(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char islower__doc__[] = -"S.islower() -> int\n\ +"S.islower() -> bool\n\ \n\ -Return 1 if all cased characters in S are lowercase and there is\n\ -at least one cased character in S, 0 otherwise."; +Return True if all cased characters in S are lowercase and there is\n\ +at least one cased character in S, False otherwise."; static PyObject* string_islower(PyStringObject *self) @@ -2450,29 +2450,29 @@ string_islower(PyStringObject *self) /* Shortcut for single character strings */ if (PyString_GET_SIZE(self) == 1) - return PyInt_FromLong(islower(*p) != 0); + return PyBool_FromLong(islower(*p) != 0); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyString_GET_SIZE(self); cased = 0; for (; p < e; p++) { if (isupper(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); else if (!cased && islower(*p)) cased = 1; } - return PyInt_FromLong(cased); + return PyBool_FromLong(cased); } static char isupper__doc__[] = -"S.isupper() -> int\n\ +"S.isupper() -> bool\n\ \n\ -Return 1 if all cased characters in S are uppercase and there is\n\ -at least one cased character in S, 0 otherwise."; +Return True if all cased characters in S are uppercase and there is\n\ +at least one cased character in S, False otherwise."; static PyObject* string_isupper(PyStringObject *self) @@ -2484,30 +2484,30 @@ string_isupper(PyStringObject *self) /* Shortcut for single character strings */ if (PyString_GET_SIZE(self) == 1) - return PyInt_FromLong(isupper(*p) != 0); + return PyBool_FromLong(isupper(*p) != 0); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyString_GET_SIZE(self); cased = 0; for (; p < e; p++) { if (islower(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); else if (!cased && isupper(*p)) cased = 1; } - return PyInt_FromLong(cased); + return PyBool_FromLong(cased); } static char istitle__doc__[] = -"S.istitle() -> int\n\ +"S.istitle() -> bool\n\ \n\ -Return 1 if S is a titlecased string, i.e. uppercase characters\n\ +Return True if S is a titlecased string, i.e. uppercase characters\n\ may only follow uncased characters and lowercase characters only cased\n\ -ones. Return 0 otherwise."; +ones. Return False otherwise."; static PyObject* string_istitle(PyStringObject *self, PyObject *uncased) @@ -2519,11 +2519,11 @@ string_istitle(PyStringObject *self, PyObject *uncased) /* Shortcut for single character strings */ if (PyString_GET_SIZE(self) == 1) - return PyInt_FromLong(isupper(*p) != 0); + return PyBool_FromLong(isupper(*p) != 0); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyString_GET_SIZE(self); cased = 0; @@ -2533,20 +2533,20 @@ string_istitle(PyStringObject *self, PyObject *uncased) if (isupper(ch)) { if (previous_is_cased) - return PyInt_FromLong(0); + return PyBool_FromLong(0); previous_is_cased = 1; cased = 1; } else if (islower(ch)) { if (!previous_is_cased) - return PyInt_FromLong(0); + return PyBool_FromLong(0); previous_is_cased = 1; cased = 1; } else previous_is_cased = 0; } - return PyInt_FromLong(cased); + return PyBool_FromLong(cased); } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 96cc5f4..a49ff70 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4109,10 +4109,10 @@ unicode_index(PyUnicodeObject *self, PyObject *args) } static char islower__doc__[] = -"S.islower() -> int\n\ +"S.islower() -> bool\n\ \n\ -Return 1 if all cased characters in S are lowercase and there is\n\ -at least one cased character in S, 0 otherwise."; +Return True if all cased characters in S are lowercase and there is\n\ +at least one cased character in S, False otherwise."; static PyObject* unicode_islower(PyUnicodeObject *self) @@ -4123,11 +4123,11 @@ unicode_islower(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) - return PyInt_FromLong(Py_UNICODE_ISLOWER(*p) != 0); + return PyBool_FromLong(Py_UNICODE_ISLOWER(*p)); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; @@ -4135,18 +4135,18 @@ unicode_islower(PyUnicodeObject *self) register const Py_UNICODE ch = *p; if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); else if (!cased && Py_UNICODE_ISLOWER(ch)) cased = 1; } - return PyInt_FromLong(cased); + return PyBool_FromLong(cased); } static char isupper__doc__[] = -"S.isupper() -> int\n\ +"S.isupper() -> bool\n\ \n\ -Return 1 if all cased characters in S are uppercase and there is\n\ -at least one cased character in S, 0 otherwise."; +Return True if all cased characters in S are uppercase and there is\n\ +at least one cased character in S, False otherwise."; static PyObject* unicode_isupper(PyUnicodeObject *self) @@ -4157,11 +4157,11 @@ unicode_isupper(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) - return PyInt_FromLong(Py_UNICODE_ISUPPER(*p) != 0); + return PyBool_FromLong(Py_UNICODE_ISUPPER(*p) != 0); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; @@ -4169,19 +4169,19 @@ unicode_isupper(PyUnicodeObject *self) register const Py_UNICODE ch = *p; if (Py_UNICODE_ISLOWER(ch) || Py_UNICODE_ISTITLE(ch)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); else if (!cased && Py_UNICODE_ISUPPER(ch)) cased = 1; } - return PyInt_FromLong(cased); + return PyBool_FromLong(cased); } static char istitle__doc__[] = -"S.istitle() -> int\n\ +"S.istitle() -> bool\n\ \n\ -Return 1 if S is a titlecased string, i.e. upper- and titlecase characters\n\ -may only follow uncased characters and lowercase characters only cased\n\ -ones. Return 0 otherwise."; +Return True if S is a titlecased string, i.e. upper- and titlecase\n\ +characters may only follow uncased characters and lowercase characters\n\ +only cased ones. Return False otherwise."; static PyObject* unicode_istitle(PyUnicodeObject *self) @@ -4192,12 +4192,12 @@ unicode_istitle(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) - return PyInt_FromLong((Py_UNICODE_ISTITLE(*p) != 0) || - (Py_UNICODE_ISUPPER(*p) != 0)); + return PyBool_FromLong((Py_UNICODE_ISTITLE(*p) != 0) || + (Py_UNICODE_ISUPPER(*p) != 0)); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; @@ -4207,27 +4207,27 @@ unicode_istitle(PyUnicodeObject *self) if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) { if (previous_is_cased) - return PyInt_FromLong(0); + return PyBool_FromLong(0); previous_is_cased = 1; cased = 1; } else if (Py_UNICODE_ISLOWER(ch)) { if (!previous_is_cased) - return PyInt_FromLong(0); + return PyBool_FromLong(0); previous_is_cased = 1; cased = 1; } else previous_is_cased = 0; } - return PyInt_FromLong(cased); + return PyBool_FromLong(cased); } static char isspace__doc__[] = -"S.isspace() -> int\n\ +"S.isspace() -> bool\n\ \n\ -Return 1 if there are only whitespace characters in S,\n\ -0 otherwise."; +Return True if there are only whitespace characters in S,\n\ +False otherwise."; static PyObject* unicode_isspace(PyUnicodeObject *self) @@ -4238,25 +4238,25 @@ unicode_isspace(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1 && Py_UNICODE_ISSPACE(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISSPACE(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char isalpha__doc__[] = -"S.isalpha() -> int\n\ +"S.isalpha() -> bool\n\ \n\ -Return 1 if all characters in S are alphabetic\n\ -and there is at least one character in S, 0 otherwise."; +Return True if all characters in S are alphabetic\n\ +and there is at least one character in S, False otherwise."; static PyObject* unicode_isalpha(PyUnicodeObject *self) @@ -4267,25 +4267,25 @@ unicode_isalpha(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1 && Py_UNICODE_ISALPHA(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISALPHA(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char isalnum__doc__[] = -"S.isalnum() -> int\n\ +"S.isalnum() -> bool\n\ \n\ -Return 1 if all characters in S are alphanumeric\n\ -and there is at least one character in S, 0 otherwise."; +Return True if all characters in S are alphanumeric\n\ +and there is at least one character in S, False otherwise."; static PyObject* unicode_isalnum(PyUnicodeObject *self) @@ -4296,25 +4296,25 @@ unicode_isalnum(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1 && Py_UNICODE_ISALNUM(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISALNUM(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char isdecimal__doc__[] = -"S.isdecimal() -> int\n\ +"S.isdecimal() -> bool\n\ \n\ -Return 1 if there are only decimal characters in S,\n\ -0 otherwise."; +Return True if there are only decimal characters in S,\n\ +False otherwise."; static PyObject* unicode_isdecimal(PyUnicodeObject *self) @@ -4325,25 +4325,25 @@ unicode_isdecimal(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1 && Py_UNICODE_ISDECIMAL(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISDECIMAL(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char isdigit__doc__[] = -"S.isdigit() -> int\n\ +"S.isdigit() -> bool\n\ \n\ -Return 1 if there are only digit characters in S,\n\ -0 otherwise."; +Return True if there are only digit characters in S,\n\ +False otherwise."; static PyObject* unicode_isdigit(PyUnicodeObject *self) @@ -4354,25 +4354,25 @@ unicode_isdigit(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1 && Py_UNICODE_ISDIGIT(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISDIGIT(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char isnumeric__doc__[] = -"S.isnumeric() -> int\n\ +"S.isnumeric() -> bool\n\ \n\ -Return 1 if there are only numeric characters in S,\n\ -0 otherwise."; +Return True if there are only numeric characters in S,\n\ +False otherwise."; static PyObject* unicode_isnumeric(PyUnicodeObject *self) @@ -4383,18 +4383,18 @@ unicode_isnumeric(PyUnicodeObject *self) /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1 && Py_UNICODE_ISNUMERIC(*p)) - return PyInt_FromLong(1); + return PyBool_FromLong(1); /* Special case for empty strings */ if (PyString_GET_SIZE(self) == 0) - return PyInt_FromLong(0); + return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISNUMERIC(*p)) - return PyInt_FromLong(0); + return PyBool_FromLong(0); } - return PyInt_FromLong(1); + return PyBool_FromLong(1); } static char join__doc__[] = @@ -4862,9 +4862,9 @@ unicode_freelistsize(PyUnicodeObject *self) #endif static char startswith__doc__[] = -"S.startswith(prefix[, start[, end]]) -> int\n\ +"S.startswith(prefix[, start[, end]]) -> bool\n\ \n\ -Return 1 if S starts with the specified prefix, otherwise return 0. With\n\ +Return True if S starts with the specified prefix, False otherwise. With\n\ optional start, test S beginning at that position. With optional end, stop\n\ comparing S at that position."; @@ -4885,7 +4885,7 @@ unicode_startswith(PyUnicodeObject *self, if (substring == NULL) return NULL; - result = PyInt_FromLong(tailmatch(self, substring, start, end, -1)); + result = PyBool_FromLong(tailmatch(self, substring, start, end, -1)); Py_DECREF(substring); return result; @@ -4893,9 +4893,9 @@ unicode_startswith(PyUnicodeObject *self, static char endswith__doc__[] = -"S.endswith(suffix[, start[, end]]) -> int\n\ +"S.endswith(suffix[, start[, end]]) -> bool\n\ \n\ -Return 1 if S ends with the specified suffix, otherwise return 0. With\n\ +Return True if S ends with the specified suffix, False otherwise. With\n\ optional start, test S beginning at that position. With optional end, stop\n\ comparing S at that position."; @@ -4916,7 +4916,7 @@ unicode_endswith(PyUnicodeObject *self, if (substring == NULL) return NULL; - result = PyInt_FromLong(tailmatch(self, substring, start, end, +1)); + result = PyBool_FromLong(tailmatch(self, substring, start, end, +1)); Py_DECREF(substring); return result; |