[Zope3-dev] Re: Python 2.4 build problem

Tim Peters tim.peters at gmail.com
Wed Jan 19 23:35:08 EST 2005


[Derrick Hudson]
>> utils.registrations() returns a 'dictionary-iterator object' in python
>> 2.3 and a 'dictionary-valueiterator object' in python 2.4 and the
>> order of iteration changed.

[Fred Drake]
> I don't know if the change in iterator type is actually responsible
> change,

Extemely unlikely -- that's a red herring.

> or if there's a change in hashing something or other.

Don't know whether it's relevant, but tuple hashing definitely changed
in 2.4, to close this bug report:

    http://www.python.org/sf/942952

It's possible (don't know) that will get (or already was) backported
to Python 2.3.5.

> Either way, relying on arbitrary ordering of an unordered
> container's presentation is wrong.

Yup.

> If the object's have meaningful comparison behaviors, a list can
> be made from the iterator and sorted before presentation.
> Too bad we're not requiring Python 2.4; we'd get to use the new
> sorted() built-in.

It's trivially easy to write before 2.4:

    def sorted(iterable):
        a_list = list(iterable)
        a_list.sort()
        return a_list

>> I'd be curious to see if anyone has a simple and clean solution
>> to this problem.  I think a unit test (instead of a doctest) would
>> work better with an equality test instead of trying to ensure a
>> deterministic order of the string representation.

> I often feel this way.

If there's actually a clear solution via that route, write the doctest as:

    >>> expected == got
   True

instead.  It would be better to canonicalize the output, though!  That
the doctest fails is an excellent predictor of that any documentation
purporting to show examples of this object type's string
representation will look wrong too (depending on the version of Python
the reader happens to be using).


More information about the Zope3-dev mailing list