summaryrefslogtreecommitdiffstats
path: root/Lib/warnings.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2014-07-11 16:50:25 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2014-07-11 16:50:25 (GMT)
commitd8089e0d04a98ab7997eff7abc9abf2a4f6854b8 (patch)
tree3690ed07fb49970ca55ce6a7fd2477232697dfda /Lib/warnings.py
parent6e1ccfe87261a9bc3818d1b4c2409eb1b7db19c5 (diff)
downloadcpython-d8089e0d04a98ab7997eff7abc9abf2a4f6854b8.zip
cpython-d8089e0d04a98ab7997eff7abc9abf2a4f6854b8.tar.gz
cpython-d8089e0d04a98ab7997eff7abc9abf2a4f6854b8.tar.bz2
Issue #16382: Improve exception message of warnings.warn() for bad category.
Initial patch by Phil Elson.
Diffstat (limited to 'Lib/warnings.py')
-rw-r--r--Lib/warnings.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py
index a427e35..f37b8a7 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -162,7 +162,9 @@ def warn(message, category=None, stacklevel=1):
# Check category argument
if category is None:
category = UserWarning
- assert issubclass(category, Warning)
+ if not (isinstance(category, type) and issubclass(category, Warning)):
+ raise TypeError("category must be a Warning subclass, "
+ "not '{:s}'".format(type(category).__name__))
# Get context information
try:
caller = sys._getframe(stacklevel)