mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Merged revisions 58886-58929 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r58892 | guido.van.rossum | 2007-11-06 15:32:56 -0800 (Tue, 06 Nov 2007) | 2 lines Add missing "return NULL" in overflow check in PyObject_Repr(). ........ r58893 | raymond.hettinger | 2007-11-06 17:13:09 -0800 (Tue, 06 Nov 2007) | 1 line Fix marshal's incorrect handling of subclasses of builtin types (backport candidate). ........ r58895 | raymond.hettinger | 2007-11-06 18:26:17 -0800 (Tue, 06 Nov 2007) | 1 line Optimize dict.fromkeys() with dict inputs. Useful for resetting bag/muliset counts for example. ........ r58896 | raymond.hettinger | 2007-11-06 18:45:46 -0800 (Tue, 06 Nov 2007) | 1 line Add build option for faster loop execution. ........ r58900 | nick.coghlan | 2007-11-07 03:57:51 -0800 (Wed, 07 Nov 2007) | 1 line Add missing NEWS entry ........ r58905 | christian.heimes | 2007-11-07 09:50:54 -0800 (Wed, 07 Nov 2007) | 1 line Backported fix for bug #1392 from py3k branch r58903. ........ r58906 | christian.heimes | 2007-11-07 10:30:22 -0800 (Wed, 07 Nov 2007) | 1 line Backport of Guido's review of my patch. ........ r58908 | raymond.hettinger | 2007-11-07 18:52:43 -0800 (Wed, 07 Nov 2007) | 1 line Add set.isdisjoint() ........ r58915 | raymond.hettinger | 2007-11-08 10:47:51 -0800 (Thu, 08 Nov 2007) | 1 line Reposition the decref (spotted by eagle-eye norwitz). ........ r58920 | georg.brandl | 2007-11-09 04:31:43 -0800 (Fri, 09 Nov 2007) | 2 lines Fix seealso link to sets docs. Do not merge to Py3k. ........ r58921 | georg.brandl | 2007-11-09 05:08:48 -0800 (Fri, 09 Nov 2007) | 2 lines Fix misleading example. ........ r58923 | georg.brandl | 2007-11-09 09:33:23 -0800 (Fri, 09 Nov 2007) | 3 lines Correct a comment about testing methods - nowadays most tests don't run directly on import. ........ r58924 | martin.v.loewis | 2007-11-09 14:56:30 -0800 (Fri, 09 Nov 2007) | 2 lines Add Amaury Forgeot d'Arc. ........ r58925 | raymond.hettinger | 2007-11-09 15:14:44 -0800 (Fri, 09 Nov 2007) | 1 line Optimize common case for dict.fromkeys(). ........ r58927 | raymond.hettinger | 2007-11-09 17:54:03 -0800 (Fri, 09 Nov 2007) | 1 line Use a freelist to speed-up block allocation and deallocation in collections.deque(). ........ r58929 | guido.van.rossum | 2007-11-10 14:12:24 -0800 (Sat, 10 Nov 2007) | 3 lines Issue 1416. Add getter, setter, deleter methods to properties that can be used as decorators to create fully-populated properties. ........
This commit is contained in:
parent
06cfe95237
commit
58da931da9
16 changed files with 349 additions and 39 deletions
|
@ -1099,6 +1099,60 @@ static PyMemberDef property_members[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
PyDoc_STRVAR(getter_doc,
|
||||
"Descriptor to change the getter on a property.");
|
||||
|
||||
PyObject *
|
||||
property_getter(PyObject *self, PyObject *getter)
|
||||
{
|
||||
Py_XDECREF(((propertyobject *)self)->prop_get);
|
||||
if (getter == Py_None)
|
||||
getter = NULL;
|
||||
Py_XINCREF(getter);
|
||||
((propertyobject *)self)->prop_get = getter;
|
||||
Py_INCREF(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(setter_doc,
|
||||
"Descriptor to change the setter on a property.\n");
|
||||
|
||||
PyObject *
|
||||
property_setter(PyObject *self, PyObject *setter)
|
||||
{
|
||||
Py_XDECREF(((propertyobject *)self)->prop_set);
|
||||
if (setter == Py_None)
|
||||
setter = NULL;
|
||||
Py_XINCREF(setter);
|
||||
((propertyobject *)self)->prop_set = setter;
|
||||
Py_INCREF(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(deleter_doc,
|
||||
"Descriptor to change the deleter on a property.");
|
||||
|
||||
PyObject *
|
||||
property_deleter(PyObject *self, PyObject *deleter)
|
||||
{
|
||||
Py_XDECREF(((propertyobject *)self)->prop_del);
|
||||
if (deleter == Py_None)
|
||||
deleter = NULL;
|
||||
Py_XINCREF(deleter);
|
||||
((propertyobject *)self)->prop_del = deleter;
|
||||
Py_INCREF(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyMethodDef property_methods[] = {
|
||||
{"getter", property_getter, METH_O, getter_doc},
|
||||
{"setter", property_setter, METH_O, setter_doc},
|
||||
{"deleter", property_deleter, METH_O, deleter_doc},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
property_dealloc(PyObject *self)
|
||||
|
@ -1251,7 +1305,7 @@ PyTypeObject PyProperty_Type = {
|
|||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
property_methods, /* tp_methods */
|
||||
property_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
|
|
|
@ -1175,6 +1175,25 @@ dict_fromkeys(PyObject *cls, PyObject *args)
|
|||
if (d == NULL)
|
||||
return NULL;
|
||||
|
||||
if (PyDict_CheckExact(d) && PyDict_CheckExact(seq)) {
|
||||
PyDictObject *mp = (PyDictObject *)d;
|
||||
PyObject *oldvalue;
|
||||
Py_ssize_t pos = 0;
|
||||
PyObject *key;
|
||||
long hash;
|
||||
|
||||
if (dictresize(mp, PySet_GET_SIZE(seq)))
|
||||
return NULL;
|
||||
|
||||
while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
|
||||
Py_INCREF(key);
|
||||
Py_INCREF(value);
|
||||
if (insertdict(mp, key, hash, value))
|
||||
return NULL;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
if (PyDict_CheckExact(d) && PyAnySet_CheckExact(seq)) {
|
||||
PyDictObject *mp = (PyDictObject *)d;
|
||||
Py_ssize_t pos = 0;
|
||||
|
@ -1199,19 +1218,24 @@ dict_fromkeys(PyObject *cls, PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
key = PyIter_Next(it);
|
||||
if (key == NULL) {
|
||||
if (PyErr_Occurred())
|
||||
if (PyDict_CheckExact(d)) {
|
||||
while ((key = PyIter_Next(it)) != NULL) {
|
||||
status = PyDict_SetItem(d, key, value);
|
||||
Py_DECREF(key);
|
||||
if (status < 0)
|
||||
goto Fail;
|
||||
}
|
||||
} else {
|
||||
while ((key = PyIter_Next(it)) != NULL) {
|
||||
status = PyObject_SetItem(d, key, value);
|
||||
Py_DECREF(key);
|
||||
if (status < 0)
|
||||
goto Fail;
|
||||
break;
|
||||
}
|
||||
status = PyObject_SetItem(d, key, value);
|
||||
Py_DECREF(key);
|
||||
if (status < 0)
|
||||
goto Fail;
|
||||
}
|
||||
|
||||
if (PyErr_Occurred())
|
||||
goto Fail;
|
||||
Py_DECREF(it);
|
||||
return d;
|
||||
|
||||
|
|
|
@ -1314,6 +1314,73 @@ set_iand(PySetObject *so, PyObject *other)
|
|||
return (PyObject *)so;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
set_isdisjoint(PySetObject *so, PyObject *other)
|
||||
{
|
||||
PyObject *key, *it, *tmp;
|
||||
|
||||
if ((PyObject *)so == other) {
|
||||
if (PySet_GET_SIZE(so) == 0)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (PyAnySet_CheckExact(other)) {
|
||||
Py_ssize_t pos = 0;
|
||||
setentry *entry;
|
||||
|
||||
if (PySet_GET_SIZE(other) > PySet_GET_SIZE(so)) {
|
||||
tmp = (PyObject *)so;
|
||||
so = (PySetObject *)other;
|
||||
other = tmp;
|
||||
}
|
||||
while (set_next((PySetObject *)other, &pos, &entry)) {
|
||||
int rv = set_contains_entry(so, entry);
|
||||
if (rv == -1)
|
||||
return NULL;
|
||||
if (rv)
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
it = PyObject_GetIter(other);
|
||||
if (it == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((key = PyIter_Next(it)) != NULL) {
|
||||
int rv;
|
||||
setentry entry;
|
||||
long hash = PyObject_Hash(key);
|
||||
|
||||
if (hash == -1) {
|
||||
Py_DECREF(key);
|
||||
Py_DECREF(it);
|
||||
return NULL;
|
||||
}
|
||||
entry.hash = hash;
|
||||
entry.key = key;
|
||||
rv = set_contains_entry(so, &entry);
|
||||
Py_DECREF(key);
|
||||
if (rv == -1) {
|
||||
Py_DECREF(it);
|
||||
return NULL;
|
||||
}
|
||||
if (rv) {
|
||||
Py_DECREF(it);
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
Py_DECREF(it);
|
||||
if (PyErr_Occurred())
|
||||
return NULL;
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(isdisjoint_doc,
|
||||
"Return True if two sets have a null intersection.");
|
||||
|
||||
static int
|
||||
set_difference_update_internal(PySetObject *so, PyObject *other)
|
||||
{
|
||||
|
@ -1839,6 +1906,8 @@ static PyMethodDef set_methods[] = {
|
|||
intersection_doc},
|
||||
{"intersection_update",(PyCFunction)set_intersection_update, METH_O,
|
||||
intersection_update_doc},
|
||||
{"isdisjoint", (PyCFunction)set_isdisjoint, METH_O,
|
||||
isdisjoint_doc},
|
||||
{"issubset", (PyCFunction)set_issubset, METH_O,
|
||||
issubset_doc},
|
||||
{"issuperset", (PyCFunction)set_issuperset, METH_O,
|
||||
|
@ -1960,6 +2029,8 @@ static PyMethodDef frozenset_methods[] = {
|
|||
difference_doc},
|
||||
{"intersection",(PyCFunction)set_intersection, METH_O,
|
||||
intersection_doc},
|
||||
{"isdisjoint", (PyCFunction)set_isdisjoint, METH_O,
|
||||
isdisjoint_doc},
|
||||
{"issubset", (PyCFunction)set_issubset, METH_O,
|
||||
issubset_doc},
|
||||
{"issuperset", (PyCFunction)set_issuperset, METH_O,
|
||||
|
|
|
@ -611,6 +611,7 @@ PyString_Repr(PyObject *obj, int smartquotes)
|
|||
if (newsize > PY_SSIZE_T_MAX || (newsize-3) / 4 != length) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"bytes object is too large to make repr");
|
||||
return NULL;
|
||||
}
|
||||
v = PyUnicode_FromUnicode(NULL, newsize);
|
||||
if (v == NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue