summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2006-06-22 16:49:14 (GMT)
committerBrett Cannon <bcannon@gmail.com>2006-06-22 16:49:14 (GMT)
commit53ab5b761d9e6e0f8b06c328508bafdb9a6a25ac (patch)
tree721af8f962a8991f6924e6834c31f2d3c3ba2756
parent56b76c8a65aafc77cbeeb326450186de1898df7f (diff)
downloadcpython-53ab5b761d9e6e0f8b06c328508bafdb9a6a25ac.zip
cpython-53ab5b761d9e6e0f8b06c328508bafdb9a6a25ac.tar.gz
cpython-53ab5b761d9e6e0f8b06c328508bafdb9a6a25ac.tar.bz2
'warning's was improperly requiring that a command-line Warning category be
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.
-rw-r--r--Lib/test/test_warnings.py13
-rw-r--r--Lib/warnings.py3
-rw-r--r--Misc/NEWS4
3 files changed, 18 insertions, 2 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index 5d051a5..4663814 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -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).
diff --git a/Lib/warnings.py b/Lib/warnings.py
index 4b4119d..939184f 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -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
diff --git a/Misc/NEWS b/Misc/NEWS
index d02f40f..ae1963f 100644
--- 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).