Skip to content

Latest commit

 

History

History
18 lines (15 loc) · 1.01 KB

22229-TAC.rst

File metadata and controls

18 lines (15 loc) · 1.01 KB

ArtistList proxies copy contents on iteration

When iterating over the contents of the dynamically generated proxy lists for the Artist-type accessors (see :ref:`Behavioural API Changes 3.5 - Axes children combined`), a copy of the contents is made. This ensure that artists can safely be added or removed from the Axes while iterating over their children.

This is a departure from the expected behavior of mutable iterable data types in Python -- iterating over list while mutating it has surprising consequences and dictionaries will error if they change size during iteration. Because all of the accessors are filtered views of the same underlying list, it is possible for seemingly unrelated changes, such as removing a Line, to affect the iteration over any of the other accessors. In this case, we have opted to make a copy of the relevant children before yielding them to the user.

This change is also consistent with our plan to make these accessors immutable in Matplotlib 3.7.