From 43eb15ed65ed710d1ad09be1486d3cfa761ea097 Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Thu, 25 Feb 2021 20:14:15 +0530 Subject: [PATCH] fix: code quality issues (#406) * Refactor unnecessary `else` / `elif` when `if` block has a `return` statement * Remove unused imports * Use literal syntax to create data structure * revert "remove unused import" --- src/dependency_injector/wiring.py | 11 +++++------ tests/unit/providers/test_callables_py2_py3.py | 2 +- tests/unit/providers/test_coroutines_py35.py | 2 +- tests/unit/providers/test_factories_py2_py3.py | 2 +- tests/unit/providers/test_list_py2_py3.py | 2 +- tests/unit/providers/test_resource_py35.py | 2 +- tests/unit/providers/test_singletons_py2_py3.py | 2 +- tests/unit/wiring/test_wiring_string_ids_py36.py | 7 +------ 8 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/dependency_injector/wiring.py b/src/dependency_injector/wiring.py index c7debfdf..96d1e238 100644 --- a/src/dependency_injector/wiring.py +++ b/src/dependency_injector/wiring.py @@ -111,21 +111,20 @@ class ProvidersMap: ) -> Optional[providers.Provider]: if isinstance(provider, providers.Delegate): return self._resolve_delegate(provider) - elif isinstance(provider, ( + if isinstance(provider, ( providers.ProvidedInstance, providers.AttributeGetter, providers.ItemGetter, providers.MethodCaller, )): return self._resolve_provided_instance(provider) - elif isinstance(provider, providers.ConfigurationOption): + if isinstance(provider, providers.ConfigurationOption): return self._resolve_config_option(provider) - elif isinstance(provider, providers.TypedConfigurationOption): + if isinstance(provider, providers.TypedConfigurationOption): return self._resolve_config_option(provider.option, as_=provider.provides) - elif isinstance(provider, str): + if isinstance(provider, str): return self._resolve_string_id(provider, modifier) - else: - return self._resolve_provider(provider) + return self._resolve_provider(provider) def _resolve_string_id( self, diff --git a/tests/unit/providers/test_callables_py2_py3.py b/tests/unit/providers/test_callables_py2_py3.py index 0e0168fa..dcee8478 100644 --- a/tests/unit/providers/test_callables_py2_py3.py +++ b/tests/unit/providers/test_callables_py2_py3.py @@ -69,7 +69,7 @@ class CallableTests(unittest.TestCase): provider = providers.Callable(_example) \ .add_args(1, 2) \ .set_args(3, 4) - self.assertEqual(provider.args, tuple([3, 4])) + self.assertEqual(provider.args, (3, 4)) def test_set_kwargs(self): provider = providers.Callable(_example) \ diff --git a/tests/unit/providers/test_coroutines_py35.py b/tests/unit/providers/test_coroutines_py35.py index a3697044..b0dbf491 100644 --- a/tests/unit/providers/test_coroutines_py35.py +++ b/tests/unit/providers/test_coroutines_py35.py @@ -87,7 +87,7 @@ class CoroutineTests(AsyncTestCase): provider = providers.Coroutine(_example) \ .add_args(1, 2) \ .set_args(3, 4) - self.assertEqual(provider.args, tuple([3, 4])) + self.assertEqual(provider.args, (3, 4)) def test_set_kwargs(self): provider = providers.Coroutine(_example) \ diff --git a/tests/unit/providers/test_factories_py2_py3.py b/tests/unit/providers/test_factories_py2_py3.py index b6587859..edf7de07 100644 --- a/tests/unit/providers/test_factories_py2_py3.py +++ b/tests/unit/providers/test_factories_py2_py3.py @@ -228,7 +228,7 @@ class FactoryTests(unittest.TestCase): provider = providers.Factory(Example) \ .add_args(1, 2) \ .set_args(3, 4) - self.assertEqual(provider.args, tuple([3, 4])) + self.assertEqual(provider.args, (3, 4)) def test_set_kwargs(self): provider = providers.Factory(Example) \ diff --git a/tests/unit/providers/test_list_py2_py3.py b/tests/unit/providers/test_list_py2_py3.py index d11222cf..e303745b 100644 --- a/tests/unit/providers/test_list_py2_py3.py +++ b/tests/unit/providers/test_list_py2_py3.py @@ -42,7 +42,7 @@ class ListTests(unittest.TestCase): provider = providers.List() \ .add_args(1, 2) \ .set_args(3, 4) - self.assertEqual(provider.args, tuple([3, 4])) + self.assertEqual(provider.args, (3, 4)) def test_clear_args(self): provider = providers.List() \ diff --git a/tests/unit/providers/test_resource_py35.py b/tests/unit/providers/test_resource_py35.py index 4b818198..b0943968 100644 --- a/tests/unit/providers/test_resource_py35.py +++ b/tests/unit/providers/test_resource_py35.py @@ -203,7 +203,7 @@ class ResourceTests(unittest.TestCase): provider = providers.Resource(init_fn) \ .add_args(1, 2) \ .set_args(3, 4) - self.assertEqual(provider.args, tuple([3, 4])) + self.assertEqual(provider.args, (3, 4)) def test_clear_args(self): provider = providers.Resource(init_fn) \ diff --git a/tests/unit/providers/test_singletons_py2_py3.py b/tests/unit/providers/test_singletons_py2_py3.py index 6cc4c3c3..4e36f926 100644 --- a/tests/unit/providers/test_singletons_py2_py3.py +++ b/tests/unit/providers/test_singletons_py2_py3.py @@ -190,7 +190,7 @@ class _BaseSingletonTestCase(object): provider = self.singleton_cls(Example) \ .add_args(1, 2) \ .set_args(3, 4) - self.assertEqual(provider.args, tuple([3, 4])) + self.assertEqual(provider.args, (3, 4)) def test_set_kwargs(self): provider = self.singleton_cls(Example) \ diff --git a/tests/unit/wiring/test_wiring_string_ids_py36.py b/tests/unit/wiring/test_wiring_string_ids_py36.py index 0acc99ce..42002372 100644 --- a/tests/unit/wiring/test_wiring_string_ids_py36.py +++ b/tests/unit/wiring/test_wiring_string_ids_py36.py @@ -1,15 +1,10 @@ -import contextlib from decimal import Decimal -import importlib import unittest from dependency_injector.wiring import ( wire, Provide, - Closing, - register_loader_containers, - unregister_loader_containers, -) + Closing) from dependency_injector import errors # Runtime import to avoid syntax errors in samples on Python < 3.5