From ff629989bb276c35b8533fe5e27e7740f5ca0de6 Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Wed, 25 Nov 2015 13:39:50 +0200 Subject: [PATCH] Make DynamicCatalog.last_overriding and DeclarativeCatalog.last_overriding attributes None by default --- dependency_injector/catalogs.py | 13 ++++++------- tests/test_catalogs.py | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/dependency_injector/catalogs.py b/dependency_injector/catalogs.py index 46ba57a3..fcc4c978 100644 --- a/dependency_injector/catalogs.py +++ b/dependency_injector/catalogs.py @@ -235,12 +235,10 @@ class DynamicCatalog(object): def last_overriding(self): """Read-only reference to the last overriding catalog, if any. - :type: :py:class:`DeclarativeCatalog` | :py:class:`DynamicCatalog` + :type: :py:class:`DeclarativeCatalog` | :py:class:`DynamicCatalog` | + None """ - try: - return self.overridden_by[-1] - except (TypeError, IndexError): - raise Error('Catalog {0} is not overridden'.format(self)) + return self.overridden_by[-1] if self.overridden_by else None def override(self, overriding): """Override current catalog providers by overriding catalog providers. @@ -477,7 +475,8 @@ class DeclarativeCatalogMetaClass(type): def last_overriding(cls): """Read-only reference to the last overriding catalog, if any. - :type: :py:class:`DeclarativeCatalog` | :py:class:`DynamicCatalog` + :type: :py:class:`DeclarativeCatalog` | :py:class:`DynamicCatalog` | + None """ return cls._catalog.last_overriding @@ -605,7 +604,7 @@ class DeclarativeCatalog(object): last_overriding = None """Read-only reference to the last overriding catalog, if any. - :type: :py:class:`DeclarativeCatalog` | :py:class:`DynamicCatalog` + :type: :py:class:`DeclarativeCatalog` | :py:class:`DynamicCatalog` | None """ _catalog = DynamicCatalog diff --git a/tests/test_catalogs.py b/tests/test_catalogs.py index 016d2cf0..7af5798a 100644 --- a/tests/test_catalogs.py +++ b/tests/test_catalogs.py @@ -506,8 +506,7 @@ class OverrideTests(unittest.TestCase): def test_last_overriding_on_not_overridden(self): """Test catalog last_overriding property on not overridden catalog.""" - with self.assertRaises(errors.Error): - CatalogA.last_overriding + self.assertIsNone(CatalogA.last_overriding) def test_reset_last_overriding(self): """Test resetting last overriding catalog."""