Commit ab3d353d authored by David Glick's avatar David Glick

empty object managers were evaluating to boolean false since Hanno fully...

empty object managers were evaluating to boolean false since Hanno fully implemented IContainer, because boolean checks fall through to __len__ if __nonzero__ is not implemented.  always evaluating to true is the backwards-compatible approach
parent 0cae9cc3
...@@ -32,6 +32,10 @@ Restructuring ...@@ -32,6 +32,10 @@ Restructuring
newer versions of the dependencies. This kind of KGS information needs newer versions of the dependencies. This kind of KGS information needs
to be expressed in a different way. to be expressed in a different way.
Bugs Fixed
++++++++++
- Object managers should evaluate to True in a boolean test.
2.12.0a1 (2009-02-26) 2.12.0a1 (2009-02-26)
--------------------- ---------------------
......
...@@ -789,6 +789,9 @@ class ObjectManager(CopyContainer, ...@@ -789,6 +789,9 @@ class ObjectManager(CopyContainer,
def __len__(self): def __len__(self):
return len(self.objectIds()) return len(self.objectIds())
def __nonzero__(self):
return True
security.declareProtected(access_contents_information, 'get') security.declareProtected(access_contents_information, 'get')
def get(self, key, default=None): def get(self, key, default=None):
return self._getOb(key, default) return self._getOb(key, default)
......
...@@ -379,6 +379,10 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase): ...@@ -379,6 +379,10 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase):
om['2'] = si2 om['2'] = si2
self.failUnless(len(om) == 2) self.failUnless(len(om) == 2)
def test_nonzero(self):
om = self._makeOne()
self.failUnless(om)
def test_get(self): def test_get(self):
om = self._makeOne() om = self._makeOne()
si1 = SimpleItem('1') si1 = SimpleItem('1')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment