diff options
author | Guido van Rossum <guido@python.org> | 2000-12-19 03:04:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-12-19 03:04:50 (GMT) |
commit | d1db30b7b5b06686ad7753d6402d762033a7ee1d (patch) | |
tree | 62469482551410de99d9ff8d6ba5c76109d3d192 | |
parent | 5aff7752eb28c6ddaa68738ee77e1947b72e1a58 (diff) | |
download | cpython-d1db30b7b5b06686ad7753d6402d762033a7ee1d.zip cpython-d1db30b7b5b06686ad7753d6402d762033a7ee1d.tar.gz cpython-d1db30b7b5b06686ad7753d6402d762033a7ee1d.tar.bz2 |
Improve error messages for invalid warning arguments; don't raise
exceptions but always print a warning message.
-rw-r--r-- | Lib/warnings.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py index 47eb19a..a894bf2 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -167,14 +167,20 @@ def _getcategory(category): if re.match("^[a-zA-Z0-9_]+$", category): try: cat = eval(category) - except KeyError: - raise _OptionError("invalid warning category: %s" % `category`) + except NameError: + raise _OptionError("unknown warning category: %s" % `category`) else: i = category.rfind(".") module = category[:i] klass = category[i+1:] - m = __import__(module, None, None, [klass]) - cat = getattr(m, klass) + try: + m = __import__(module, None, None, [klass]) + except ImportError: + raise _OptionError("invalid module name: %s" % `module`) + try: + cat = getattr(m, klass) + except AttributeError: + raise _OptionError("unknown warning category: %s" % `category`) if (not isinstance(cat, types.ClassType) or not issubclass(cat, Warning)): raise _OptionError("invalid warning category: %s" % `category`) |