[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.249,2.250 marshal.c,1.70,1.71
Guido van Rossum
gvanrossum@users.sourceforge.net
Wed, 03 Apr 2002 14:41:53 -0800
- Previous message: [Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.122,2.123 fileobject.c,2.153,2.154 intobject.c,2.80,2.81 object.c,2.169,2.170 stringobject.c,2.153,2.154 unicodeobject.c,2.133,2.134
- Next message: [Python-checkins] CVS: python/dist/src/Doc/whatsnew whatsnew23.tex,1.4,1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv31419/Python
Modified Files:
bltinmodule.c marshal.c
Log Message:
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.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.249
retrieving revision 2.250
diff -C2 -d -r2.249 -r2.250
*** bltinmodule.c 9 Mar 2002 12:07:51 -0000 2.249
--- bltinmodule.c 3 Apr 2002 22:41:51 -0000 2.250
***************
*** 131,139 ****
builtin_callable(PyObject *self, PyObject *v)
{
! return PyInt_FromLong((long)PyCallable_Check(v));
}
static char callable_doc[] =
! "callable(object) -> Boolean\n\
\n\
Return whether the object is callable (i.e., some kind of function).\n\
--- 131,139 ----
builtin_callable(PyObject *self, PyObject *v)
{
! return PyBool_FromLong((long)PyCallable_Check(v));
}
static char callable_doc[] =
! "callable(object) -> bool\n\
\n\
Return whether the object is callable (i.e., some kind of function).\n\
***************
*** 714,718 ****
static char hasattr_doc[] =
! "hasattr(object, name) -> Boolean\n\
\n\
Return whether the object has an attribute with the given name.\n\
--- 714,718 ----
static char hasattr_doc[] =
! "hasattr(object, name) -> bool\n\
\n\
Return whether the object has an attribute with the given name.\n\
***************
*** 1667,1675 ****
if (retval < 0)
return NULL;
! return PyInt_FromLong(retval);
}
static char isinstance_doc[] =
! "isinstance(object, class-or-type-or-tuple) -> Boolean\n\
\n\
Return whether an object is an instance of a class or of a subclass thereof.\n\
--- 1667,1675 ----
if (retval < 0)
return NULL;
! return PyBool_FromLong(retval);
}
static char isinstance_doc[] =
! "isinstance(object, class-or-type-or-tuple) -> bool\n\
\n\
Return whether an object is an instance of a class or of a subclass thereof.\n\
***************
*** 1692,1700 ****
if (retval < 0)
return NULL;
! return PyInt_FromLong(retval);
}
static char issubclass_doc[] =
! "issubclass(C, B) -> Boolean\n\
\n\
Return whether class C is a subclass (i.e., a derived class) of class B.";
--- 1692,1700 ----
if (retval < 0)
return NULL;
! return PyBool_FromLong(retval);
}
static char issubclass_doc[] =
! "issubclass(C, B) -> bool\n\
\n\
Return whether class C is a subclass (i.e., a derived class) of class B.";
***************
*** 1857,1860 ****
--- 1857,1863 ----
SETBUILTIN("Ellipsis", Py_Ellipsis);
SETBUILTIN("NotImplemented", Py_NotImplemented);
+ SETBUILTIN("False", Py_False);
+ SETBUILTIN("True", Py_True);
+ SETBUILTIN("bool", &PyBool_Type);
SETBUILTIN("classmethod", &PyClassMethod_Type);
#ifndef WITHOUT_COMPLEX
***************
*** 1880,1884 ****
SETBUILTIN("unicode", &PyUnicode_Type);
#endif
! debug = PyInt_FromLong(Py_OptimizeFlag == 0);
if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
Py_XDECREF(debug);
--- 1883,1887 ----
SETBUILTIN("unicode", &PyUnicode_Type);
#endif
! debug = PyBool_FromLong(Py_OptimizeFlag == 0);
if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
Py_XDECREF(debug);
Index: marshal.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/marshal.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** marshal.c 31 Mar 2002 14:37:44 -0000 1.70
--- marshal.c 3 Apr 2002 22:41:51 -0000 1.71
***************
*** 18,21 ****
--- 18,23 ----
#define TYPE_NULL '0'
#define TYPE_NONE 'N'
+ #define TYPE_FALSE 'F'
+ #define TYPE_TRUE 'T'
#define TYPE_STOPITER 'S'
#define TYPE_ELLIPSIS '.'
***************
*** 127,130 ****
--- 129,138 ----
w_byte(TYPE_ELLIPSIS, p);
}
+ else if (v == Py_False) {
+ w_byte(TYPE_FALSE, p);
+ }
+ else if (v == Py_True) {
+ w_byte(TYPE_TRUE, p);
+ }
else if (PyInt_Check(v)) {
long x = PyInt_AS_LONG((PyIntObject *)v);
***************
*** 398,401 ****
--- 406,417 ----
Py_INCREF(Py_Ellipsis);
return Py_Ellipsis;
+
+ case TYPE_FALSE:
+ Py_INCREF(Py_False);
+ return Py_False;
+
+ case TYPE_TRUE:
+ Py_INCREF(Py_True);
+ return Py_True;
case TYPE_INT:
- Previous message: [Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.122,2.123 fileobject.c,2.153,2.154 intobject.c,2.80,2.81 object.c,2.169,2.170 stringobject.c,2.153,2.154 unicodeobject.c,2.133,2.134
- Next message: [Python-checkins] CVS: python/dist/src/Doc/whatsnew whatsnew23.tex,1.4,1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]