This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Setting category fails with -W switch
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: akuchling, brett.cannon
Priority: normal Keywords:

Created on 2006-06-22 12:20 by akuchling, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
warning-test.patch akuchling, 2006-06-22 13:50 Add simple tests for warning option parsing
Messages (5)
msg28861 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-06-22 12:20
This command reports an "invalid warning category"
error, but it shouldn't.

./python -W'ignore:Not importing directory:ImportWarning'

I think the change to new-style exceptions exposed this
problem.  warnings.py contains the following code to
trigger this error:

    if (not isinstance(cat, types.ClassType) or
        not issubclass(cat, Warning)):
        raise _OptionError("invalid warning category:
%r" % (category,))

The new-style exceptions mean that the first
isinstance() now returns False.   I think there may be
two fixes needed.  First, I think it should be
"isinstance(cat, types.ClassType) or isinstance(cat,
type)".

Second issue: hould the warnings.py code use "and"
instead of "or"?  Surely if issubclass(cat, Warning) is
True, the category is certainly OK; no?
msg28862 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-06-22 13:50
Logged In: YES 
user_id=11375

Once the problem is fixed, the attached patch adds some
tests for warning parsing.
msg28863 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2006-06-22 16:05
Logged In: YES 
user_id=357491

Well, the docs for warnings
(http://docs.python.org/dev/lib/warning-categories.html) say
that a category must subclass Warning.  So I removed the
ClassType check entirely, and that causes test_exceptions to
segfault.  Lovely.

I will try to look at this Friday.
msg28864 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2006-06-22 16:13
Logged In: YES 
user_id=357491

Turns out Armin's r47061 checkin fixed it; for some reason I
had not rebuilt.  Doing a distclean and re-running tests
before committing the change.
msg28865 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2006-06-22 16:49
Logged In: YES 
user_id=357491

r47072 has just the check for the subclass of Warning and
added your tests.  Thanks, Andrew.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43536
2006-06-22 12:20:11akuchlingcreate