Commit 53ab5b76 authored by Brett Cannon's avatar Brett Cannon

'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.
parent 56b76c8a
...@@ -81,6 +81,19 @@ class TestModule(unittest.TestCase): ...@@ -81,6 +81,19 @@ class TestModule(unittest.TestCase):
self.assertEqual(msg.message, text) self.assertEqual(msg.message, text)
self.assertEqual(msg.category, 'UserWarning') 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): def test_main(verbose=None):
# Obscure hack so that this test passes after reloads or repeated calls # Obscure hack so that this test passes after reloads or repeated calls
# to test_main (regrtest -R). # to test_main (regrtest -R).
......
...@@ -254,8 +254,7 @@ def _getcategory(category): ...@@ -254,8 +254,7 @@ def _getcategory(category):
cat = getattr(m, klass) cat = getattr(m, klass)
except AttributeError: except AttributeError:
raise _OptionError("unknown warning category: %r" % (category,)) raise _OptionError("unknown warning category: %r" % (category,))
if (not isinstance(cat, types.ClassType) or if not issubclass(cat, Warning):
not issubclass(cat, Warning)):
raise _OptionError("invalid warning category: %r" % (category,)) raise _OptionError("invalid warning category: %r" % (category,))
return cat return cat
......
...@@ -16,6 +16,10 @@ Core and builtins ...@@ -16,6 +16,10 @@ Core and builtins
Library 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 - The compiler module now correctly compiles the new try-except-finally
statement (bug #1509132). statement (bug #1509132).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment