mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Make Provider.last_overriding None by default
This commit is contained in:
parent
dd80bb3c17
commit
b7f42a3ff4
|
@ -76,12 +76,9 @@ class Provider(object):
|
|||
def last_overriding(self):
|
||||
"""Read-only reference to the last overriding provider, if any.
|
||||
|
||||
:type: :py:class:`Provider`
|
||||
:type: :py:class:`Provider` | None
|
||||
"""
|
||||
try:
|
||||
return self.overridden_by[-1]
|
||||
except (TypeError, IndexError):
|
||||
raise Error('Provider {0} is not overridden'.format(str(self)))
|
||||
return self.overridden_by[-1] if self.overridden_by else None
|
||||
|
||||
def override(self, provider):
|
||||
"""Override provider with another provider.
|
||||
|
@ -104,7 +101,7 @@ class Provider(object):
|
|||
|
||||
:rtype: None
|
||||
"""
|
||||
if not self.is_overridden:
|
||||
if not self.overridden_by:
|
||||
raise Error('Provider {0} is not overridden'.format(str(self)))
|
||||
self.overridden_by = self.overridden_by[:-1]
|
||||
|
||||
|
|
|
@ -90,13 +90,7 @@ class ProviderTests(unittest.TestCase):
|
|||
|
||||
def test_last_overriding_of_not_overridden_provider(self):
|
||||
"""Test getting last overriding from not overridden provider."""
|
||||
try:
|
||||
self.provider.last_overriding
|
||||
except errors.Error:
|
||||
pass
|
||||
else:
|
||||
self.fail('Got en error in {}'.format(
|
||||
str(self.test_last_overriding_of_not_overridden_provider)))
|
||||
self.assertIsNone(self.provider.last_overriding)
|
||||
|
||||
def test_reset_last_overriding(self):
|
||||
"""Test reseting of last overriding provider."""
|
||||
|
@ -129,13 +123,7 @@ class ProviderTests(unittest.TestCase):
|
|||
self.provider.reset_override()
|
||||
|
||||
self.assertFalse(self.provider.is_overridden)
|
||||
try:
|
||||
self.provider.last_overriding
|
||||
except errors.Error:
|
||||
pass
|
||||
else:
|
||||
self.fail('Got en error in {}'.format(
|
||||
str(self.test_last_overriding_of_not_overridden_provider)))
|
||||
self.assertIsNone(self.provider.last_overriding)
|
||||
|
||||
|
||||
class DelegateTests(unittest.TestCase):
|
||||
|
|
Loading…
Reference in New Issue
Block a user