[ python-Bugs-1463840 ] logging.StreamHandler ignores argument if it compares False
SourceForge.net
noreply at sourceforge.net
Tue Apr 4 08:20:17 CEST 2006
Bugs item #1463840, was opened at 2006-04-03 14:37
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1463840&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Paul Winkler (slinkp)
>Assigned to: Vinay Sajip (vsajip)
Summary: logging.StreamHandler ignores argument if it compares False
Initial Comment:
The docs at http://docs.python.org/lib/node346.html say
this:
"""
class StreamHandler( [strm])
Returns a new instance of the StreamHandler class.
If strm is specified, the instance will use it for
logging output; otherwise, sys.stderr will be used.
"""
However, that's not quite true.
StreamHandler.__init__() actually tests for truth of
strm, which means you have to be careful that strm does
not happen to evaluate to boolean false.
My use case: I'm writing some tests that verify that
certain methods put certain strings into the logs. So
my setUp() adds a StreamHandler with its stream set to
an instance of this trivial class:
class FakeLog(list):
def write(self, msg):
self.append(msg)
def flush(self):
pass
... which does not work, because an empty list
evaluates to false, so my handler writes to stderr even
though i told it not to. It's trivial to work around
this by adding a __nonzero__ method, but the need to do
so is certainly not clear from the docs. Therefore imho
this is a bug. The patch is trivial, and is attached.
----------------------------------------------------------------------
>Comment By: Neal Norwitz (nnorwitz)
Date: 2006-04-03 23:20
Message:
Logged In: YES
user_id=33168
Vinay, any comments? We are preparing for 2.5 alpha1 within
a day. There will be freeze real soon now.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1463840&group_id=5470
More information about the Python-bugs-list
mailing list