On Sat, Aug 1, 2020 at 6:10 PM Inada Naoki <songofaca...@gmail.com> wrote:

> Repacking is mutation, and mutating dict while iterating it breaks the
> iterator.
> But `d.items()[42]` don't looks like mutation.
>

Pardon my ignorance, but IS repacking a mutation? Clearly it's mutating the
internal state, but at the logical structure of the dict will not have
changed.

Though I suppose if it's being iterated over, then the iterator is keeping
an index into the internal array, which would change on repacking?

which means that it's worse than not looking like a mutation, but it could
make active iterators return results that are actually incorrect.

I have to think that this could be accommodated somehow, but with ugly
special case code, so yeah, not worth it. Though you could keep track of if
there are any active views (ir even active iterators) and not repack in
that case. I'm sure most dict iterators are most commonly used right away.

Is repacking ever currently done with dicts? If so, then how is this issue
worked around?

-CHB


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/U3NKOPESDAYHQ5Z6ZUFTR3IL6YCUWXPQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to