From c008a957dff5058ed220a8b1ce5e76772d41daaf Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 16 Oct 2012 12:59:22 -0400 Subject: [PATCH] added a __contains__ method that looks for a special property _ndict_contains__ (must be a function) when present, the in operator behavior will be determined by the return of the special property. --- zipline/utils/protocol_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zipline/utils/protocol_utils.py b/zipline/utils/protocol_utils.py index c027a70c..4c6f04d7 100644 --- a/zipline/utils/protocol_utils.py +++ b/zipline/utils/protocol_utils.py @@ -96,6 +96,14 @@ class ndict(MutableMapping): def __len__(self): return len(self.__internal) + #TODO: Eddie please help! + def __contains__(self, key): + if hasattr(self, '_ndict_contains__'): + return self._ndict_contains__(key) + else: + return self.__internal.__contains__(key) + + # Compatability with namedicts # ----------------------------