[Python-checkins] r47072 - in python/trunk: Lib/test/test_warnings.py Lib/warnings.py Misc/NEWS
brett.cannon
python-checkins at python.org
Thu Jun 22 18:49:15 CEST 2006
Author: brett.cannon
Date: Thu Jun 22 18:49:14 2006
New Revision: 47072
Modified:
python/trunk/Lib/test/test_warnings.py
python/trunk/Lib/warnings.py
python/trunk/Misc/NEWS
Log:
'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.
Modified: python/trunk/Lib/test/test_warnings.py
==============================================================================
--- python/trunk/Lib/test/test_warnings.py (original)
+++ python/trunk/Lib/test/test_warnings.py Thu Jun 22 18:49:14 2006
@@ -81,6 +81,19 @@
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).
Modified: python/trunk/Lib/warnings.py
==============================================================================
--- python/trunk/Lib/warnings.py (original)
+++ python/trunk/Lib/warnings.py Thu Jun 22 18:49:14 2006
@@ -254,8 +254,7 @@
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
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Thu Jun 22 18:49:14 2006
@@ -16,6 +16,10 @@
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).
More information about the Python-checkins
mailing list