File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1344,7 +1344,7 @@ def test_bytearray_translate(self):
13441344 self .assertRaises (TypeError , x .translate , b"1" * 256 , 1 )
13451345
13461346 def test_construct_singletons (self ):
1347- for const in None , Ellipsis :
1347+ for const in None , Ellipsis , NotImplemented :
13481348 tp = type (const )
13491349 self .assertIs (tp (), const )
13501350 self .assertRaises (TypeError , tp , 1 , 2 )
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ What's New in Python 3.3 Alpha 1?
1010Core and Builtins
1111-----------------
1212
13- - Make type(None) and type(Ellipsis ) callable. They return the respective
14- singleton instances.
13+ - Make type(None), type(Ellipsis), and type(NotImplemented ) callable. They
14+ return the respective singleton instances.
1515
1616- Forbid summing bytes in sum().
1717
Original file line number Diff line number Diff line change @@ -1385,6 +1385,17 @@ NotImplemented_repr(PyObject *op)
13851385 return PyUnicode_FromString ("NotImplemented" );
13861386}
13871387
1388+ static PyObject *
1389+ notimplemented_new (PyTypeObject * type , PyObject * args , PyObject * kwargs )
1390+ {
1391+ if (PyTuple_GET_SIZE (args ) || (kwargs && PyDict_Size (kwargs ))) {
1392+ PyErr_SetString (PyExc_TypeError , "NotImplementedType takes no arguments" );
1393+ return NULL ;
1394+ }
1395+ Py_INCREF (Py_NotImplemented );
1396+ return Py_NotImplemented ;
1397+ }
1398+
13881399static PyTypeObject PyNotImplemented_Type = {
13891400 PyVarObject_HEAD_INIT (& PyType_Type , 0 )
13901401 "NotImplementedType" ,
@@ -1400,6 +1411,30 @@ static PyTypeObject PyNotImplemented_Type = {
14001411 0 , /*tp_as_sequence*/
14011412 0 , /*tp_as_mapping*/
14021413 0 , /*tp_hash */
1414+ 0 , /*tp_call */
1415+ 0 , /*tp_str */
1416+ 0 , /*tp_getattro */
1417+ 0 , /*tp_setattro */
1418+ 0 , /*tp_as_buffer */
1419+ Py_TPFLAGS_DEFAULT , /*tp_flags */
1420+ 0 , /*tp_doc */
1421+ 0 , /*tp_traverse */
1422+ 0 , /*tp_clear */
1423+ 0 , /*tp_richcompare */
1424+ 0 , /*tp_weaklistoffset */
1425+ 0 , /*tp_iter */
1426+ 0 , /*tp_iternext */
1427+ 0 , /*tp_methods */
1428+ 0 , /*tp_members */
1429+ 0 , /*tp_getset */
1430+ 0 , /*tp_base */
1431+ 0 , /*tp_dict */
1432+ 0 , /*tp_descr_get */
1433+ 0 , /*tp_descr_set */
1434+ 0 , /*tp_dictoffset */
1435+ 0 , /*tp_init */
1436+ 0 , /*tp_alloc */
1437+ notimplemented_new , /*tp_new */
14031438};
14041439
14051440PyObject _Py_NotImplementedStruct = {
You can’t perform that action at this time.
0 commit comments