diff -r 80f07777accd Lib/test/test_sys.py --- a/Lib/test/test_sys.py Mon Oct 17 19:33:38 2011 +0200 +++ b/Lib/test/test_sys.py Tue Oct 18 00:13:16 2011 +0200 @@ -432,6 +432,13 @@ self.assertEqual(type(getattr(sys.flags, attr)), int, attr) self.assertTrue(repr(sys.flags)) + def test_sys_flags_no_instantiation(self): + flags_type = type(sys.flags) + with self.assertRaises(TypeError): + flags_type() + with self.assertRaises(TypeError): + flags_type.__new__(flags_type) + def test_clear_type_cache(self): sys._clear_type_cache() diff -r 80f07777accd Python/sysmodule.c --- a/Python/sysmodule.c Mon Oct 17 19:33:38 2011 +0200 +++ b/Python/sysmodule.c Tue Oct 18 00:13:16 2011 +0200 @@ -1339,6 +1339,7 @@ PyObject *m, *v, *sysdict; PyObject *sysin, *sysout, *syserr; char *s; + int res; m = Py_InitModule3("sys", sys_methods, sys_doc); if (m == NULL) @@ -1476,6 +1477,9 @@ /* prevent user from creating new instances */ VersionInfoType.tp_init = NULL; VersionInfoType.tp_new = NULL; + res = PyDict_DelItemString(VersionInfoType.tp_dict, "__new__"); + if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) + PyErr_Clear(); /* flags */ if (FlagsType.tp_name == 0) @@ -1484,7 +1488,9 @@ /* prevent user from creating new instances */ FlagsType.tp_init = NULL; FlagsType.tp_new = NULL; - + res = PyDict_DelItemString(FlagsType.tp_dict, "__new__"); + if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) + PyErr_Clear(); #if defined(MS_WINDOWS) /* getwindowsversion */ @@ -1493,6 +1499,9 @@ /* prevent user from creating new instances */ WindowsVersionType.tp_init = NULL; WindowsVersionType.tp_new = NULL; + res = PyDict_DelItemString(WindowsVersionType.tp_dict, "__new__"); + if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) + PyErr_Clear(); #endif /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */