mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-16 19:40:59 +03:00
Add UndefinedProviderError(Error, AttributeError) for proper work of hasattr()
This commit is contained in:
parent
9a617479cc
commit
ed898f7fe2
|
@ -3,6 +3,7 @@
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from .errors import Error
|
from .errors import Error
|
||||||
|
from .errors import UndefinedProviderError
|
||||||
|
|
||||||
from .utils import is_provider
|
from .utils import is_provider
|
||||||
from .utils import is_catalog
|
from .utils import is_catalog
|
||||||
|
@ -54,7 +55,8 @@ class CatalogBundle(object):
|
||||||
"""Raise an error on every attempt to get undefined provider."""
|
"""Raise an error on every attempt to get undefined provider."""
|
||||||
if item.startswith('__') and item.endswith('__'):
|
if item.startswith('__') and item.endswith('__'):
|
||||||
return super(CatalogBundle, self).__getattr__(item)
|
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):
|
def __repr__(self):
|
||||||
"""Return string representation of catalog bundle."""
|
"""Return string representation of catalog bundle."""
|
||||||
|
@ -149,8 +151,8 @@ class DynamicCatalog(object):
|
||||||
try:
|
try:
|
||||||
return self.providers[name]
|
return self.providers[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise Error('{0} has no provider with such name - {1}'.format(
|
raise UndefinedProviderError('{0} has no provider with such '
|
||||||
self, name))
|
'name - {1}'.format(self, name))
|
||||||
|
|
||||||
def bind_provider(self, name, provider):
|
def bind_provider(self, name, provider):
|
||||||
"""Bind provider to catalog with specified name."""
|
"""Bind provider to catalog with specified name."""
|
||||||
|
|
|
@ -3,3 +3,7 @@
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
"""Base error."""
|
"""Base error."""
|
||||||
|
|
||||||
|
|
||||||
|
class UndefinedProviderError(Error, AttributeError):
|
||||||
|
"""Undefined provider error."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user