On 30 Aug, 2006, at 15:09, Phillip J. Eby wrote:

We could do that, after we got rid of any existing code that depends on the old semantics of enumerations.

However, it should be noted that this may lead to interesting problems in schema upgrades. My understanding is that the reason for wanting explicit values (as opposed to simple sequence) is that it allows constant values to be preserved across releases, even if things are added or removed. Second, it allows the use of enumerations as constants for interacting with external systems, like socket mode flags and such.

I guess I can get the behaviour I want with the lovely:

values = dict(map(reversed, enumerate(("done", "now", "later"))))


The backward compatibility point is a good one. BTW, if in α5 we decide we need a "soon" between "now" and "later", would

        values = {"now": 0, "later": 1, "done": -1, "soon": 0.5}

work?

--Grant


At 03:04 PM 8/30/2006 -0700, Grant Baillie wrote:
Perhaps I should've been more explicit :o). Instead of

    class TriageEnum(schema.Enumeration):
        values = {"now": 0, "later": 1, "done": -1}

I would rather just write:

    class TriageEnum(schema.Enumeration):
        values = "done", "now", "later"

to produce the same values TriageEnum.done, TriageEnum.now, etc. (The
values would be auto-generated, but would sort the same as the dict
example).

--Grant


On 30 Aug, 2006, at 14:38, 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?

--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

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

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

Reply via email to