diff -r 5ea81e4c58a7 Lib/test/test_sys.py --- a/Lib/test/test_sys.py Mon Oct 17 20:44:22 2011 +0200 +++ b/Lib/test/test_sys.py Mon Oct 17 23:47:24 2011 +0200 @@ -520,6 +520,13 @@ self.assertTrue(repr(sys.flags)) self.assertEqual(len(sys.flags), len(attrs)) + 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 5ea81e4c58a7 Python/sysmodule.c --- a/Python/sysmodule.c Mon Oct 17 20:44:22 2011 +0200 +++ b/Python/sysmodule.c Mon Oct 17 23:47:24 2011 +0200 @@ -1471,6 +1471,7 @@ { PyObject *m, *v, *sysdict; char *s; + int res; m = PyModule_Create(&sysmodule); if (m == NULL) @@ -1589,6 +1590,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) @@ -1597,7 +1601,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 */ @@ -1606,6 +1612,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) */