Brett Hannigan <brett.hanni...@gmail.com> added the comment:
I encountered the need for the iterators when trying to create a subclass of the QueueHandler class that would manage both the QueueHandler and the QueueListener. The implementation is very similar to that described in this Medium post: https://medium.com/@rob.blackbourn/how-to-use-python-logging-queuehandler-with-dictconfig-1e8b1284e27a Both the original poster and I encountered one small issue: when using a dictConfig to instantiate the new subclass, the main QueueHandler gets a ConvertingList of the handlers that the user has requested be used. The subclass would then pass these to the QueueListener, but the constructor for the QueueListener takes *handlers (that is, it will convert the ConvertingList to a tuple). Unfortunately, because ConvertingList does not expose the iterator, converting from the ConvertingList to the tuple results in a tuple of unconverted handler references (ultimately strings). The author of the Medium article gets around this by creating a little function that simply loops over the length of the ConvertingList and does a "get" on each item on the list, to ensure that the item is converted. Since ConvertingList is not documented though, there is concern that this approach could break in the future if the interface changes etc. With the implementation of the iterator in this PR, the conversion of the ConvertingList to the tuple will automatically result in a tuple of converted handlers, so one doesn't need to know about the ConvertingList object - it handles things behind the scenes. Here is the code that the Medium article currently uses to force conversion: def _resolve_handlers(l): if not isinstance(l, ConvertingList): return l # Indexing the list performs the evaluation. return [l[i] for i in range(len(l))] ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41177> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com