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.

Author godot_gildor
Recipients godot_gildor, mivade, python-dev, serhiy.storchaka, vinay.sajip
Date 2020-07-06.14:59:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594047559.46.0.37375335446.issue41177@roundup.psfhosted.org>
In-reply-to
Content
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))]
History
Date User Action Args
2020-07-06 14:59:19godot_gildorsetrecipients: + godot_gildor, vinay.sajip, python-dev, serhiy.storchaka, mivade
2020-07-06 14:59:19godot_gildorsetmessageid: <1594047559.46.0.37375335446.issue41177@roundup.psfhosted.org>
2020-07-06 14:59:19godot_gildorlinkissue41177 messages
2020-07-06 14:59:19godot_gildorcreate