summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-06-27 00:31:13 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-06-27 00:31:13 (GMT)
commitdea1b5653ffd2183c7a4d577a2ca08644dd51248 (patch)
treedc441e1ddb4884a57e4fc305fa77f87b7a100578 /Lib
parent80821f7cf4b2af64e444ad71ca13eb96fcbd6454 (diff)
downloadcpython-dea1b5653ffd2183c7a4d577a2ca08644dd51248.zip
cpython-dea1b5653ffd2183c7a4d577a2ca08644dd51248.tar.gz
cpython-dea1b5653ffd2183c7a4d577a2ca08644dd51248.tar.bz2
warnings.warn_explicit() did not have the proper TypeErrors in place to prevent
bus errors or SystemError being raised. As a side effect of fixing this, a bad DECREF that could be triggered when 'message' and 'category' were both None was fixed. Closes issue 3211. Thanks JP Calderone for the bug report.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_warnings.py15
-rw-r--r--Lib/warnings.py1
2 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index fdb003f..ed498e0 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -301,6 +301,21 @@ class WarnTests(unittest.TestCase):
warning_tests.__name__ = module_name
sys.argv = argv
+ def test_warn_explicit_type_errors(self):
+ # warn_explicit() shoud error out gracefully if it is given objects
+ # of the wrong types.
+ # lineno is expected to be an integer.
+ self.assertRaises(TypeError, self.module.warn_explicit,
+ None, UserWarning, None, None)
+ # Either 'message' needs to be an instance of Warning or 'category'
+ # needs to be a subclass.
+ self.assertRaises(TypeError, self.module.warn_explicit,
+ None, None, None, 1)
+ # 'registry' must be a dict or None.
+ self.assertRaises((TypeError, AttributeError),
+ self.module.warn_explicit,
+ None, Warning, None, 1, registry=42)
+
class CWarnTests(BaseTest, WarnTests):
diff --git a/Lib/warnings.py b/Lib/warnings.py
index d9e6e44..2e5c512 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -202,6 +202,7 @@ def warn(message, category=None, stacklevel=1):
def warn_explicit(message, category, filename, lineno,
module=None, registry=None, module_globals=None):
+ lineno = int(lineno)
if module is None:
module = filename or "<unknown>"
if module[-3:].lower() == ".py":