From 3c0629e6a9eac41abf386175803a9fcb9d5a6eb2 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 14 Jun 2013 17:52:57 +0200 Subject: [PATCH] better raise message if try to launch impl_get_information/impl_set_information in uncompatible class --- tiramisu/option.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tiramisu/option.py b/tiramisu/option.py index 46ad5e9..1c14efc 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -64,19 +64,27 @@ class BaseInformation(object): :param key: information's key (ex: "help", "doc" :param value: information's value (ex: "the help string") """ - self._impl_informations[key] = value + try: + self._impl_informations[key] = value + except AttributeError: + raise AttributeError(_('{0} instance has no attribute ' + 'impl_set_information').format(self.__class__.__name__)) def impl_get_information(self, key, default=None): """retrieves one information's item :param key: the item string (ex: "help") """ - if key in self._impl_informations: - return self._impl_informations[key] - elif default is not None: - return default - else: - raise ValueError(_("Information's item not found: {0}").format(key)) + try: + if key in self._impl_informations: + return self._impl_informations[key] + elif default is not None: + return default + else: + raise ValueError(_("Information's item not found: {0}").format(key)) + except AttributeError: + raise AttributeError(_('{0} instance has no attribute ' + 'impl_get_information').format(self.__class__.__name__)) class Option(BaseInformation):