the constructor functions work with any iterable Python object.
+.. cfunction:: int PySet_Check(PyObject *p)
+
+ Return true if *p* is a :class:`set` object or an instance of a subtype.
+
+ .. versionadded:: 2.6
+
.. cfunction:: int PyAnySet_Check(PyObject *p)
Return true if *p* is a :class:`set` object, a :class:`frozenset` object, or an
set on success or *NULL* on failure. Raise :exc:`TypeError` if *iterable* is
not actually iterable.
+ .. versionchanged:: 2.6
+ Now guaranteed to return a brand-new :class:`frozenset`. Formerly,
+ frozensets of zero-length were a singleton. This got in the way of
+ building-up new frozensets with :meth:`PySet_Add`.
+
The following functions and macros are available for instances of :class:`set`
or :class:`frozenset` or instances of their subtypes.
the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
:class:`set`, :class:`frozenset`, or an instance of a subtype.
-The following functions are available for instances of :class:`set` or its
-subtypes but not for instances of :class:`frozenset` or its subtypes.
-
.. cfunction:: int PySet_Add(PyObject *set, PyObject *key)
Raise a :exc:`SystemError` if *set* is an not an instance of :class:`set` or its
subtype.
+ .. versionchanged:: 2.6
+ Now works with instances of :class:`frozenset` or its subtypes.
+ Like :cfunc:`PyTuple_SetItem` in that it can be used to fill-in the
+ values of brand new frozensets before they are exposed to other code.
+
+The following functions are available for instances of :class:`set` or its
+subtypes but not for instances of :class:`frozenset` or its subtypes.
+
.. cfunction:: int PySet_Discard(PyObject *set, PyObject *key)
(Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \
PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \
PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))
+#define PySet_Check(ob) \
+ (Py_TYPE(ob) == &PySet_Type || PyType_IsSubtype(Py_TYPE(ob), &PySet_Type))
PyAPI_FUNC(PyObject *) PySet_New(PyObject *);
PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);
self.failUnlessEqual(strtok(None, b"\n"), "c")
self.failUnlessEqual(strtok(None, b"\n"), None)
- def test_NULL_funcptr(self):
- tp = CFUNCTYPE(c_int)
- func = tp() # NULL function pointer
- # raise a ValueError when we try to call it
- self.assertRaises(ValueError, func)
-
if __name__ == '__main__':
unittest.main()
# Run reindent on the library
reindent:
- ./python$(EXEEXT) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
+ ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
# Rerun configure with the same options as it was run last time,
# provided the config.status script exists
-" Auto-generated Vim syntax file for Python
+" Auto-generated Vim syntax file for Python (trunk: r60376M).
"
" To use: copy or symlink to ~/.vim/syntax/python.vim
if exists("python_highlight_builtins")
syn keyword pythonBuiltin Ellipsis False None NotImplemented True __debug__
- syn keyword pythonBuiltin __import__ abs all any basestring bool
+ syn keyword pythonBuiltin __import__ abs all any bool
syn keyword pythonBuiltin buffer callable chr classmethod cmp
syn keyword pythonBuiltin complex copyright credits delattr dict
syn keyword pythonBuiltin dir divmod enumerate eval exec exit
syn keyword pythonBuiltin max min object oct open ord pow property quit
syn keyword pythonBuiltin range reload repr reversed round
syn keyword pythonBuiltin set setattr slice sorted staticmethod str sum
- syn keyword pythonBuiltin super tuple type unichr unicode vars zip
+ syn keyword pythonBuiltin super trunc tuple type unicode vars
+ syn keyword pythonBuiltin zip
endif
Not necessarily sensical or comprehensive (assume that if one exception is
highlighted that all are, for instance).
-Highlighting extraneous whitespace at the end of the line is not represented
-here as all trailing whitespace is automatically removed from .py files in the
-repository.
+Extraneous trailing whitespace can't be tested because of svn pre-commit hook
+checks for such things.
"""
# Comment
import exceptions
import builtins
from string import Template
+from sys import subversion
-comment_header = '''" Auto-generated Vim syntax file for Python.
+comment_header = '''" Auto-generated Vim syntax file for Python (%s: r%s).
"
" To use: copy or symlink to ~/.vim/syntax/python.vim'''
def main(file_path):
with open(file_path, 'w') as FILE:
# Comment for file
- print>>FILE, comment_header
+ print>>FILE, comment_header % subversion[1:]
print>>FILE, ''
# Statements at start of file
print>>FILE, statement_header
pProc = *(void **)self->b_ptr;
- if (pProc == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "attempt to call NULL function pointer");
- return NULL;
- }
#ifdef MS_WIN32
if (self->index) {
/* It's a COM method */
PyObject *
PyFrozenSet_New(PyObject *iterable)
{
- PyObject *args, *result;
-
- if (iterable == NULL)
- args = PyTuple_New(0);
- else
- args = PyTuple_Pack(1, iterable);
- if (args == NULL)
- return NULL;
- result = frozenset_new(&PyFrozenSet_Type, args, NULL);
- Py_DECREF(args);
- return result;
+ return make_new_set(&PyFrozenSet_Type, iterable);
}
Py_ssize_t
int
PySet_Clear(PyObject *set)
{
- if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
+ if (!PySet_Check(set)) {
PyErr_BadInternalCall();
return -1;
}
int
PySet_Discard(PyObject *set, PyObject *key)
{
- if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
+ if (!PySet_Check(set)) {
PyErr_BadInternalCall();
return -1;
}
}
int
-PySet_Add(PyObject *set, PyObject *key)
+PySet_Add(PyObject *anyset, PyObject *key)
{
- if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
+ if (!PyAnySet_Check(anyset)) {
PyErr_BadInternalCall();
return -1;
}
- return set_add_key((PySetObject *)set, key);
+ return set_add_key((PySetObject *)anyset, key);
}
int
PyObject *
PySet_Pop(PyObject *set)
{
- if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
+ if (!PySet_Check(set)) {
PyErr_BadInternalCall();
return NULL;
}
int
_PySet_Update(PyObject *set, PyObject *iterable)
{
- if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
+ if (!PySet_Check(set)) {
PyErr_BadInternalCall();
return -1;
}
f = PyFrozenSet_New(dup);
assert(PySet_Size(f) == 3);
assert(PyFrozenSet_CheckExact(f));
- assertRaises(PySet_Add(f, elem) == -1, PyExc_SystemError);
assertRaises(PySet_Discard(f, elem) == -1, PyExc_SystemError);
assertRaises(PySet_Pop(f) == NULL, PyExc_SystemError);
Py_DECREF(f);
retval = NULL;
break;
}
- v = PyTuple_New((int)n);
+ v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL);
if (v == NULL) {
retval = NULL;
break;
v = NULL;
break;
}
- PyTuple_SET_ITEM(v, (int)i, v2);
- }
- if (v == NULL) {
- retval = NULL;
- break;
+ if (PySet_Add(v, v2) == -1) {
+ Py_DECREF(v);
+ Py_DECREF(v2);
+ v = NULL;
+ break;
+ }
}
- if (type == TYPE_SET)
- v3 = PySet_New(v);
- else
- v3 = PyFrozenSet_New(v);
- Py_DECREF(v);
- retval = v3;
+ retval = v;
break;
case TYPE_CODE:
# a release. Most open source OSes come with one or more
# versions of BerkeleyDB already installed.
- max_db_ver = (4, 6)
+ max_db_ver = (4, 5) # XXX(gregory.p.smith): 4.6 "works" but seems to
+ # have issues on many platforms. I've temporarily
+ # disabled 4.6 to see what the odd platform
+ # buildbots say.
min_db_ver = (3, 3)
db_setup_debug = False # verbose debug prints from this script?