]> granicus.if.org Git - python/commitdiff
SF #1486663 -- Allow keyword args in subclasses of set() and frozenset().
authorRaymond Hettinger <python@rcn.com>
Thu, 11 Jan 2007 18:21:04 +0000 (18:21 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 11 Jan 2007 18:21:04 +0000 (18:21 +0000)
Lib/test/test_set.py
Objects/setobject.c

index dedd1fb5e599cfdb995df5cd5964f8e4e62f0c16..49bdec344547944c0ebdb32a158906bb8558ce9e 100644 (file)
@@ -468,6 +468,16 @@ class SetSubclass(set):
 class TestSetSubclass(TestSet):
     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):
     thetype = frozenset
 
@@ -1450,6 +1460,7 @@ def test_main(verbose=None):
     test_classes = (
         TestSet,
         TestSetSubclass,
+        TestSetSubclassWithKeywordArgs,        
         TestFrozenSet,
         TestFrozenSetSubclass,
         TestSetOfSets,
index 507a07bdcc785617ead5e687f7736b3b3f6b2721..f038ee3fdeb7dd6d07f58bf32422f503a206bcab 100644 (file)
@@ -1004,7 +1004,7 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
        PyObject *iterable = NULL, *result;
 
-       if (!_PyArg_NoKeywords("frozenset()", kwds))
+       if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds))
                return NULL;
 
        if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable))
@@ -1048,7 +1048,7 @@ PySet_Fini(void)
 static PyObject *
 set_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-       if (!_PyArg_NoKeywords("set()", kwds))
+       if (type == &PySet_Type && !_PyArg_NoKeywords("set()", kwds))
                return NULL;
        
        return make_new_set(type, NULL);