From 98bef8ccf2bd4afb16af7c79ab03fadc8b2082ff Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Mon, 23 Dec 2013 21:58:43 +0100 Subject: [PATCH] Fix util.LazyObject for wrapping None --- mutalyzer/config/__init__.py | 4 ++-- mutalyzer/util.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mutalyzer/config/__init__.py b/mutalyzer/config/__init__.py index 4d8d9940..0ca16a75 100644 --- a/mutalyzer/config/__init__.py +++ b/mutalyzer/config/__init__.py @@ -68,7 +68,7 @@ class LazySettings(util.LazyObject): """ Called to manually configure the settings. """ - if self._wrapped is None: + if self._wrapped is util.empty: self._setup(from_environment=False) self._wrapped.update(settings) @@ -87,7 +87,7 @@ class LazySettings(util.LazyObject): """ Returns True if the settings have already been configured. """ - return self._wrapped is not None + return self._wrapped is not util.empty def on_update(self, callback, key=None): """ diff --git a/mutalyzer/util.py b/mutalyzer/util.py index a367f31b..702584c0 100644 --- a/mutalyzer/util.py +++ b/mutalyzer/util.py @@ -917,10 +917,14 @@ class AttributeDictMixin(object): self[key] = value +# This is used in LazyObject to define the empty wrapper. +empty = object() + + # Helper for LazyObject. def _new_method_proxy(func): def inner(self, *args): - if self._wrapped is None: + if self._wrapped is empty: self._setup() return func(self._wrapped, *args) return inner @@ -937,7 +941,7 @@ class LazyObject(object): _wrapped = None def __init__(self): - self._wrapped = None + self._wrapped = empty __getattr__ = _new_method_proxy(getattr) @@ -946,14 +950,14 @@ class LazyObject(object): # Assign to __dict__ to avoid infinite __setattr__ loops. self.__dict__['_wrapped'] = value else: - if self._wrapped is None: + if self._wrapped is empty: self._setup() setattr(self._wrapped, name, value) def __delattr__(self, name): if name == '_wrapped': raise TypeError('can\'t delete _wrapped.') - if self._wrapped is None: + if self._wrapped is empty: self._setup() delattr(self._wrapped, name) -- GitLab