Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1db30b

Browse files
committed
Improve error messages for invalid warning arguments; don't raise
exceptions but always print a warning message.
1 parent 5aff775 commit d1db30b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/warnings.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,20 @@ def _getcategory(category):
167167
if re.match("^[a-zA-Z0-9_]+$", category):
168168
try:
169169
cat = eval(category)
170-
except KeyError:
171-
raise _OptionError("invalid warning category: %s" % `category`)
170+
except NameError:
171+
raise _OptionError("unknown warning category: %s" % `category`)
172172
else:
173173
i = category.rfind(".")
174174
module = category[:i]
175175
klass = category[i+1:]
176-
m = __import__(module, None, None, [klass])
177-
cat = getattr(m, klass)
176+
try:
177+
m = __import__(module, None, None, [klass])
178+
except ImportError:
179+
raise _OptionError("invalid module name: %s" % `module`)
180+
try:
181+
cat = getattr(m, klass)
182+
except AttributeError:
183+
raise _OptionError("unknown warning category: %s" % `category`)
178184
if (not isinstance(cat, types.ClassType) or
179185
not issubclass(cat, Warning)):
180186
raise _OptionError("invalid warning category: %s" % `category`)

0 commit comments

Comments
 (0)