Issue #16382: Improve exception message of warnings.warn() for bad category.

Initial patch by Phil Elson.
This commit is contained in:
Berker Peksag 2014-07-11 19:50:25 +03:00
parent 6e1ccfe872
commit d8089e0d04
4 changed files with 48 additions and 7 deletions

View file

@ -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)