Add UndefinedProviderError(Error, AttributeError) for proper work of hasattr()

This commit is contained in:
Roman Mogilatov 2015-11-11 19:14:56 +02:00
parent 9a617479cc
commit ed898f7fe2
2 changed files with 9 additions and 3 deletions

View File

@ -3,6 +3,7 @@
import six
from .errors import Error
from .errors import UndefinedProviderError
from .utils import is_provider
from .utils import is_catalog
@ -54,7 +55,8 @@ class CatalogBundle(object):
"""Raise an error on every attempt to get undefined provider."""
if item.startswith('__') and item.endswith('__'):
return super(CatalogBundle, self).__getattr__(item)
raise Error('Provider "{0}" is not a part of {1}'.format(item, self))
raise UndefinedProviderError('Provider "{0}" is not a part '
'of {1}'.format(item, self))
def __repr__(self):
"""Return string representation of catalog bundle."""
@ -149,8 +151,8 @@ class DynamicCatalog(object):
try:
return self.providers[name]
except KeyError:
raise Error('{0} has no provider with such name - {1}'.format(
self, name))
raise UndefinedProviderError('{0} has no provider with such '
'name - {1}'.format(self, name))
def bind_provider(self, name, provider):
"""Bind provider to catalog with specified name."""

View File

@ -3,3 +3,7 @@
class Error(Exception):
"""Base error."""
class UndefinedProviderError(Error, AttributeError):
"""Undefined provider error."""