On Wed, 30 Aug 2006, Phillip J. Eby wrote:
Because dictionaries aren't ordered.
At 02:07 PM 8/30/2006 -0700, Grant Baillie wrote:
Hmm.... Why not just have the declaration order be the sort order?
Well, I think what Grant meant was why didn't I just change the simple string
enumeration we've had for ever to just sort on declaration order.
That's, as implemented, not possible, since the values of the simple enum are
strings not the constants I just introduced.
Now, if there is consensus for yet another enum that behaves like what I think
Grant is suggesting I can sure add it too.
Andi..
--Grant
On 30 Aug, 2006, at 13:57, Andi Vajda wrote:
While implementating Chandler's dashboard Bryan found that he
needed better control over the sorting of enumeration values.
Currently, enumeration values are strings and are sorted as such.
For example, if one defines an enumeration with the schema API as
follows:
class TriageEnum(schema.Enumeration):
values = "now", "later", "done"
The values of this enumeration will be sorted as:
"done" < "later" < "now"
Enter a new type of enumeration, an enumeration of constants. Such
constants have a name and a value and are sorted on their value
first. Multiple constants in an enum may have the same value, their
name is used next in sorting.
By using a dict for the enumeration's values instead of a tuple,
one can define such a constant enumeration with the schema API:
class TriageEnum(schema.Enumeration):
values = {"now": 0, "later": 1, "done": -1}
Upon definition, the TriageEnum class gets assigned three
attributes called 'now', 'later' and 'done' that contain such a
constant:
TriageEnum.now -> TriageEnum.now
TriageEnum.now.value -> 0
TriageEnum.now.name -> 'now'
repr(TriageEnum.now) -> 'TriageEnum.now'
str(TriageEnum.name) -> 'now'
These constants are sorted by their values:
TriageEnum.done < TriageEnum.now < TriageEnum.later
Andi..
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Open Source Applications Foundation "chandler-dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/chandler-dev
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Open Source Applications Foundation "chandler-dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/chandler-dev