mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Issue #16382: Improve exception message of warnings.warn() for bad category.
Initial patch by Phil Elson.
This commit is contained in:
parent
6e1ccfe872
commit
d8089e0d04
4 changed files with 48 additions and 7 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue