[ python-Bugs-1721372 ] emphasize iteration volatility for set

SourceForge.net noreply at sourceforge.net
Sat May 19 15:09:36 CEST 2007


Bugs item #1721372, was opened at 2007-05-18 10:10
Message generated for change (Comment added) made by aisaac0
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1721372&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Documentation
Group: None
Status: Closed
Resolution: Rejected
Priority: 5
Private: No
Submitted By: Alan (aisaac0)
Assigned to: Nobody/Anonymous (nobody)
Summary: emphasize iteration volatility for set

Initial Comment:
For <URL:http://docs.python.org/lib/types-set.html>, append the following new sentence to the 2nd paragraph.

    Iteration over a set returns elements in an indeterminate order, which generally depends on factors outside the scope of the containing program.

*Justification:* users should not be expected to understand without being told that iteration order depends on factors outside the scope of the containing program. (Additionally, unlike the documentation for dictionaries, the documentation for sets fails to give a serious warning not to rely on iteration order.)


----------------------------------------------------------------------

>Comment By: Alan (aisaac0)
Date: 2007-05-19 08:09

Message:
Logged In: YES 
user_id=1025672
Originator: YES

The previous comment completely misses the point.  Again, please see the
discussion on c.l.python.  Not one of the participants expected sets to be
"ordered". What was suprising to them was the order can *change* across
sequential executions of an **unchanged** source.   This is of course
*quite* different than expecting that sets are ordered; I am perplexed that
anyone would conflate the two.  One cannot credibly argue that anyone who
understands that sets are not ordered will not be surprised, since even
sophisticated users were as a matter of fact surprised in the c.l.python
discussion.  (Until it was explained by Peter of course.)  A natural
conclusion is that the docs should offer better protection against such
surprise, since we have concrete evidence that even sophisticated users can
be surprised by this.

In sum, the previous comment conflates two distinct issues and so fails to
address the reasons for the proposed docs patch.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2007-05-19 01:38

Message:
Logged In: YES 
user_id=21627
Originator: NO

The documentation already says "Being an unordered collection, sets do not
record element position or order of insertion."

If users read this and fail to understand the notion of an unordered
collection, I see no way of "fixing" this.

----------------------------------------------------------------------

Comment By: Alan (aisaac0)
Date: 2007-05-18 21:28

Message:
Logged In: YES 
user_id=1025672
Originator: YES

While I do not mind my language being rejected, *something* should be
added to warn users.  What the previous comment fails to mention is the
number of people on c.l.python, some of whom are quite sophisticated users,
who failed to discover the source of indeterminacy.  Users should not have
to "rediscover" this because of a documentation failure.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2007-05-18 18:08

Message:
Logged In: YES 
user_id=80475
Originator: NO

While the OP knows what he means here, the suggested text does not add
clarity, it only makes the subject harder to understand and implies that
some mysterious, dark force is in place.  Further, the suggested text is
simply incorrect.  Given deterministic assignment of hash values and a
consistent insertion order, the order of keys in a set or dictionary is
fully determined.

I've read the source of this suggestion on comp.lang.python and commented
there.  The underlying issue had nothing to do with either sets or dicts. 
The code in question "re-discovered" that the location of objects in memory
 would vary between runs if the user deleted a pyc file for a module.  The
OP's script used object ids as hash values, hence the set/dict ordering
could vary between runs.  This was at odds with his expectation that that
the ordering would be deterministic.  The moral is that non-deterministic
hash values lead to non-deterministic set/dict ordering.

The docs for sets and dicts should not be muddled with tangential
discussions about implementation specific details regarding what governs
where objects are placed in memory.


----------------------------------------------------------------------

Comment By: Alan (aisaac0)
Date: 2007-05-18 13:00

Message:
Logged In: YES 
user_id=1025672
Originator: YES

Location in memory.
See Peter Otten's discussion at
http://www.thescripts.com/forum/post2552380-16.html

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2007-05-18 12:05

Message:
Logged In: YES 
user_id=21627
Originator: NO

What factors outside the containing program influence iteration order?
Iteration is completely deterministic, and only depends on the items
inserted, and the order in which they were inserted, neither of which is
outside the scope of the containing program. It's just that the order is
not easily predictable.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1721372&group_id=5470


More information about the Python-bugs-list mailing list