On Tue, 23 Jan 2007, Bryan Stearns wrote:

Empty is a singleton, "item.attribute is Empty" is valid, safe code.
"item.attribute is Empty" is only "safe" at the application level if the implementation of reflist attributes puts Empty in the attribute when the last reference is removed. Otherwise, Empty is not the thing to check if you're concerned about emptiness.

Does Empty get assigned to newly-empty reflist attributes automatically?

Not at all. Empty is not assigned into anything automatically.
In my earlier statement I meant to say that you don't have to say:
  "item.attribute == Empty"
since there is only one such Empty object per process:
  "item.attribute is Empty" is safe

but if item.attribute is an empty ref list then item.attribute is not Empty.

In others words, it is always safe to say "item.attribute is None" as opposed to "item.attribute == None". The same is true the same way about Empty.

As some famous politician once said "it all depends on what the meaning of 'is' is". Here 'is' means pointer equality, it doesn't mean emptiness of the collection.

Andi..

ps: that being said, to test emptiness of the collection, testing 'collection'
    or len(collection) is better anyway. list(Empty) == [] because Empty is a
    null iterator and len(Empty) == 0 too.
    To test emptiness, if Empty is a default value on the collection
    attribute, it is now safe to say: if not item.attribute whether you have a
    values in the collection or not. That was also the case with None as a
    default values but with None, you can't safely say:
      for blah in item.attribute:
    With Empty as a default value you can.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Open Source Applications Foundation "chandler-dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/chandler-dev

Reply via email to