[Python-ideas] Add pop_callback to deque signature

Antoine Pitrou solipsis at pitrou.net
Wed Oct 4 08:38:31 EDT 2017


On Wed, 4 Oct 2017 08:47:46 +0300
Serhiy Storchaka <storchaka at gmail.com>
wrote:
> 04.10.17 07:58, Nick Coghlan пише:
> > For deque specifically, I like Steven D'Aprano's suggestion of a
> > "__dropped__" or "__discard__" subclassing API that makes it
> > straightforward to change the way that queue overruns are handled
> > (especially if raising an exception from the new subclass method can
> > prevent the collection modification entirely - that way you could
> > readily change the deque semantics in a subclass such that if the
> > queue fills up, submitters start getting errors instead of silently
> > discarding older messages, allowing backpressure to be more easily
> > propagated through a system of queues).  
> 
> Wouldn't this harm performance? Looking up the attribute of the type is 
> more costly than pushing/popping the item in the deque.

You would only do that for subtypes, so when Py_TYPE(self) is different
from the base type.  This is a simple pointer comparison.

Nick's idea sounds nice to me, as long as there's an actual use case :-)

Regards

Antoine.




More information about the Python-ideas mailing list