SF #1486663 -- Allow keyword args in subclasses of set() and frozenset().

This commit is contained in:
Raymond Hettinger 2007-01-11 18:21:04 +00:00
parent 9e031c7c9d
commit 535989ecb6
2 changed files with 13 additions and 2 deletions

View File

@ -468,6 +468,16 @@ class SetSubclass(set):
class TestSetSubclass(TestSet): class TestSetSubclass(TestSet):
thetype = SetSubclass thetype = SetSubclass
class SetSubclassWithKeywordArgs(set):
def __init__(self, iterable=[], newarg=None):
set.__init__(self, iterable)
class TestSetSubclassWithKeywordArgs(TestSet):
def test_keywords_in_subclass(self):
'SF bug #1486663 -- this used to erroneously raise a TypeError'
SetSubclassWithKeywordArgs(newarg=1)
class TestFrozenSet(TestJointOps): class TestFrozenSet(TestJointOps):
thetype = frozenset thetype = frozenset
@ -1450,6 +1460,7 @@ def test_main(verbose=None):
test_classes = ( test_classes = (
TestSet, TestSet,
TestSetSubclass, TestSetSubclass,
TestSetSubclassWithKeywordArgs,
TestFrozenSet, TestFrozenSet,
TestFrozenSetSubclass, TestFrozenSetSubclass,
TestSetOfSets, TestSetOfSets,

View File

@ -1004,7 +1004,7 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PyObject *iterable = NULL, *result; PyObject *iterable = NULL, *result;
if (!_PyArg_NoKeywords("frozenset()", kwds)) if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds))
return NULL; return NULL;
if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable))
@ -1048,7 +1048,7 @@ PySet_Fini(void)
static PyObject * static PyObject *
set_new(PyTypeObject *type, PyObject *args, PyObject *kwds) set_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
if (!_PyArg_NoKeywords("set()", kwds)) if (type == &PySet_Type && !_PyArg_NoKeywords("set()", kwds))
return NULL; return NULL;
return make_new_set(type, NULL); return make_new_set(type, NULL);