simplify __getattr__

This commit is contained in:
Emmanuel Garette 2018-08-02 19:22:44 +02:00
parent ebeaee620b
commit c46480a7eb
2 changed files with 4 additions and 19 deletions

View File

@ -314,13 +314,8 @@ class TiramisuOptionOption(CommonTiramisuOption):
return option.impl_getrequires()
def __getattr__(self, name: str) -> Callable:
#if not self._get_option().impl_is_optiondescription() and name != 'get_option':
if not self._get_option().impl_is_optiondescription():
subkey = '_' + name
if subkey in dir(self):
func = getattr(self, subkey)
if callable(func):
return func
return getattr(self, '_' + name)
raise APIError(_('{} is unknown').format(name))
def isoptiondescription(self):
@ -631,18 +626,9 @@ class TiramisuOption(CommonTiramisu):
self.subconfig,
self.config_bag,
self.option_bag)
elif subfunc == 'make_dict' and self._get_option().impl_is_optiondescription():
return self._make_dict
elif subfunc == 'find' and self._get_option().impl_is_optiondescription():
return self._find
elif subfunc == 'get' and self._get_option().impl_is_optiondescription():
return self._get
elif subfunc == 'list' and self._get_option().impl_is_optiondescription():
return self._list
elif subfunc == 'group_type' and self._get_option().impl_is_optiondescription():
return self._group_type
else:
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
elif self._get_option().impl_is_optiondescription():
return getattr(self, '_' + subfunc)
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
@count
def _make_dict(self,

View File

@ -735,7 +735,6 @@ class Config(_CommonConfig):
weakref.ref(self),
ConfigBag(self),
None)
#undocumented option used only in test script
if _duplicate is False and (force_settings is None or force_values is None):
self._impl_build_all_caches()
self._impl_name = session_id