]> granicus.if.org Git - python/commitdiff
'warning's was improperly requiring that a command-line Warning category be
authorBrett Cannon <bcannon@gmail.com>
Thu, 22 Jun 2006 16:49:14 +0000 (16:49 +0000)
committerBrett Cannon <bcannon@gmail.com>
Thu, 22 Jun 2006 16:49:14 +0000 (16:49 +0000)
both a subclass of Warning and a subclass of types.ClassType.  The latter is no
longer true thanks to new-style exceptions.

Closes bug #1510580.  Thanks to AMK for the test.

Lib/test/test_warnings.py
Lib/warnings.py
Misc/NEWS

index 5d051a59d1b6e0d957cbbe4bccb44b01b9c24ac4..46638149a9f0bda781177113ac983f4a45db6dc5 100644 (file)
@@ -81,6 +81,19 @@ class TestModule(unittest.TestCase):
         self.assertEqual(msg.message, text)
         self.assertEqual(msg.category, 'UserWarning')
 
+    def test_options(self):
+        # Uses the private _setoption() function to test the parsing
+        # of command-line warning arguments
+        self.assertRaises(warnings._OptionError,
+                          warnings._setoption, '1:2:3:4:5:6')
+        self.assertRaises(warnings._OptionError,
+                          warnings._setoption, 'bogus::Warning')
+        self.assertRaises(warnings._OptionError,
+                          warnings._setoption, 'ignore:2::4:-5')
+        warnings._setoption('error::Warning::0')
+        self.assertRaises(UserWarning, warnings.warn, 'convert to error')
+        
+
 def test_main(verbose=None):
     # Obscure hack so that this test passes after reloads or repeated calls
     # to test_main (regrtest -R).
index 4b4119dd94e7593ad8ecc85a3e9e756442e0f7d9..939184f7cacf878fc5f8f35f03f9444ae6fbf2b4 100644 (file)
@@ -254,8 +254,7 @@ def _getcategory(category):
             cat = getattr(m, klass)
         except AttributeError:
             raise _OptionError("unknown warning category: %r" % (category,))
-    if (not isinstance(cat, types.ClassType) or
-        not issubclass(cat, Warning)):
+    if not issubclass(cat, Warning):
         raise _OptionError("invalid warning category: %r" % (category,))
     return cat
 
index d02f40fd6870816c0e35ad58c742beab91435937..ae1963f6793456d70f71f4a61c8b846039b5f9d7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,10 @@ Core and builtins
 Library
 -------
 
+- Bug #1510580: The 'warnings' module improperly required that a Warning
+  category be either a types.ClassType and a subclass of Warning.  The proper
+  check is just that it is a subclass with Warning as the documentation states.
+
 - The compiler module now correctly compiles the new try-except-finally
   statement (bug #1509132).