On Wed, Aug 5, 2009 at 2:01 PM, Guido Trotter<[email protected]> wrote:
> If a value is None, there's no point exporting it in the relevant dict
> representation for an object: it will be None again when the object is
> loaded by FromDict. This has the nice side effect of removing
> "deprecated" slots from the config file.
>
> __getstate__ is also modified to filter out None members.
>
> Signed-off-by: Guido Trotter <[email protected]>
> ---
>  lib/objects.py |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lib/objects.py b/lib/objects.py
> index 6be372b..e199a05 100644
> --- a/lib/objects.py
> +++ b/lib/objects.py
> @@ -107,7 +107,7 @@ class ConfigObject(object):
>   def __getstate__(self):
>     state = {}
>     for name in self.__slots__:
> -      if hasattr(self, name):
> +      if hasattr(self, name) and getattr(self, name) is not None:

Or even better:
+      if getattr(self, name, None) is not None:

>         state[name] = getattr(self, name)
>     return state
>

Thanks,

Guido

Reply via email to