[Python-Dev] cpython (3.3): Make the various iterators' "setstate" sliently and consistently clip the
Kristján Valur Jónsson
kristjan at ccpgames.com
Mon Mar 24 10:25:58 CET 2014
Hi there.
I didn’t see the original email in python-dev, sorry about that.
The “setstate” of the iterators is primarily used when unpickling them. This is code that was added during the PyCon sprints 2012, IIRC.
Some iterators already did the silent clipping.
One did not (rangeiter), it raised a valueerror, but it did so at the wrong index, so that an iterator could not be set to the “exhausted” state.
Others did no checking, allowing the value to be set to an state that would cause undefined behavior.
The change is to prevent the last case. It is there purely for paranoid reasons. There should be no reason why a iterator should be unpickled such that its range and position would be mismatching and no reason to bloat the code with diagnostic error code for that, but still, guarding us from undefined states is essential.
If you think I should be adding exceptions for this, then I can do that.
The reason this didn’t go through the tracker is that this is code from myself and the Stackless sprint that didn’t itself go through the tracker at the time. There really Is no one more qualified to verify this code than myself ☺
K
From: Larry Hastings [mailto:larry at midwinter.com] On Behalf Of Larry Hastings
Sent: 24. mars 2014 01:33
To: Kristján Valur Jónsson
Subject: Fwd: Re: [Python-Dev] cpython (3.3): Make the various iterators' "setstate" sliently and consistently clip the
Still no reply on this...? I'd like to see your answer too.
/arry
-------- Original Message --------
Subject:
Re: [Python-Dev] cpython (3.3): Make the various iterators' "setstate" sliently and consistently clip the
Date:
Sat, 08 Mar 2014 08:01:23 +0100
From:
Georg Brandl <g.brandl at gmx.net><mailto:g.brandl at gmx.net>
To:
python-dev at python.org<mailto:python-dev at python.org>
Am 06.03.2014 09:02, schrieb Serhiy Storchaka:
> 05.03.14 17:24, kristjan.jonsson написав(ла):
>> http://hg.python.org/cpython/rev/3b2c28061184
>> changeset: 89477:3b2c28061184
>> branch: 3.3
>> parent: 89475:24d4e52f4f87
>> user: Kristján Valur Jónsson <sweskman at gmail.com><mailto:sweskman at gmail.com>
>> date: Wed Mar 05 13:47:57 2014 +0000
>> summary:
>> Make the various iterators' "setstate" sliently and consistently clip the
>> index. This avoids the possibility of setting an iterator to an invalid
>> state.
>
> Why indexes are silently clipped instead of raising an exception?
>
>> files:
>> Lib/test/test_range.py | 12 ++++++++++
>> Modules/arraymodule.c | 2 +
>> Objects/bytearrayobject.c | 10 ++++++--
>> Objects/bytesobject.c | 10 ++++++--
>> Objects/listobject.c | 2 +
>> Objects/rangeobject.c | 31 +++++++++++++++++++++++---
>> Objects/tupleobject.c | 4 +-
>> Objects/unicodeobject.c | 10 ++++++--
>> 8 files changed, 66 insertions(+), 15 deletions(-)
>
> And it would be better first discuss and review such large changes on
> the bugtracker.
Agreed. Kristjan, could you please explain a bit more about this change
and use the tracker in the future?
Georg
_______________________________________________
Python-Dev mailing list
Python-Dev at python.org<mailto:Python-Dev at python.org>
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/larry%40hastings.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140324/5149a58c/attachment-0001.html>
More information about the Python-Dev
mailing list