Bugs item #1463840, was opened at 2006-04-03 17:37 Message generated for change (Tracker Item Submitted) made by Item Submitter 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: Nobody/Anonymous (nobody) 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. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1463840&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com