Commits

Benjamin Peterson committed 9130b48

Fix logic error in Python/_warnings.c and add a test to verify

  • Participants
  • Parent commits ddd5f42
  • Branches legacy-trunk

Comments (0)

Files changed (2)

Lib/test/test_warnings.py

                 result = stream.getvalue()
         self.failUnless(text in result)
 
+    def test_showwarning_not_callable(self):
+        self.module.filterwarnings("always", category=UserWarning)
+        old_showwarning = self.module.showwarning
+        self.module.showwarning = 23
+        try:
+            self.assertRaises(TypeError, self.module.warn, "Warning!")
+        finally:
+            self.module.showwarning = old_showwarning
+
     def test_show_warning_output(self):
         # With showarning() missing, make sure that output is okay.
         text = 'test show_warning'

Python/_warnings.c

                     PyErr_SetString(PyExc_TypeError,
                                     "warnings.showwarning() must be set to a "
                                     "function or method");
+                    Py_DECREF(show_fxn);
+                    goto cleanup;
                 }
 
                 defaults = PyFunction_GetDefaults(check_fxn);