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"
This commit is contained in:
Shubhendra Singh Chauhan 2021-02-25 20:14:15 +05:30 committed by GitHub
parent 5f6777db19
commit 43eb15ed65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 12 additions and 18 deletions

View File

@ -111,21 +111,20 @@ class ProvidersMap:
) -> Optional[providers.Provider]: ) -> Optional[providers.Provider]:
if isinstance(provider, providers.Delegate): if isinstance(provider, providers.Delegate):
return self._resolve_delegate(provider) return self._resolve_delegate(provider)
elif isinstance(provider, ( if isinstance(provider, (
providers.ProvidedInstance, providers.ProvidedInstance,
providers.AttributeGetter, providers.AttributeGetter,
providers.ItemGetter, providers.ItemGetter,
providers.MethodCaller, providers.MethodCaller,
)): )):
return self._resolve_provided_instance(provider) return self._resolve_provided_instance(provider)
elif isinstance(provider, providers.ConfigurationOption): if isinstance(provider, providers.ConfigurationOption):
return self._resolve_config_option(provider) 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) 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) return self._resolve_string_id(provider, modifier)
else: return self._resolve_provider(provider)
return self._resolve_provider(provider)
def _resolve_string_id( def _resolve_string_id(
self, self,

View File

@ -69,7 +69,7 @@ class CallableTests(unittest.TestCase):
provider = providers.Callable(_example) \ provider = providers.Callable(_example) \
.add_args(1, 2) \ .add_args(1, 2) \
.set_args(3, 4) .set_args(3, 4)
self.assertEqual(provider.args, tuple([3, 4])) self.assertEqual(provider.args, (3, 4))
def test_set_kwargs(self): def test_set_kwargs(self):
provider = providers.Callable(_example) \ provider = providers.Callable(_example) \

View File

@ -87,7 +87,7 @@ class CoroutineTests(AsyncTestCase):
provider = providers.Coroutine(_example) \ provider = providers.Coroutine(_example) \
.add_args(1, 2) \ .add_args(1, 2) \
.set_args(3, 4) .set_args(3, 4)
self.assertEqual(provider.args, tuple([3, 4])) self.assertEqual(provider.args, (3, 4))
def test_set_kwargs(self): def test_set_kwargs(self):
provider = providers.Coroutine(_example) \ provider = providers.Coroutine(_example) \

View File

@ -228,7 +228,7 @@ class FactoryTests(unittest.TestCase):
provider = providers.Factory(Example) \ provider = providers.Factory(Example) \
.add_args(1, 2) \ .add_args(1, 2) \
.set_args(3, 4) .set_args(3, 4)
self.assertEqual(provider.args, tuple([3, 4])) self.assertEqual(provider.args, (3, 4))
def test_set_kwargs(self): def test_set_kwargs(self):
provider = providers.Factory(Example) \ provider = providers.Factory(Example) \

View File

@ -42,7 +42,7 @@ class ListTests(unittest.TestCase):
provider = providers.List() \ provider = providers.List() \
.add_args(1, 2) \ .add_args(1, 2) \
.set_args(3, 4) .set_args(3, 4)
self.assertEqual(provider.args, tuple([3, 4])) self.assertEqual(provider.args, (3, 4))
def test_clear_args(self): def test_clear_args(self):
provider = providers.List() \ provider = providers.List() \

View File

@ -203,7 +203,7 @@ class ResourceTests(unittest.TestCase):
provider = providers.Resource(init_fn) \ provider = providers.Resource(init_fn) \
.add_args(1, 2) \ .add_args(1, 2) \
.set_args(3, 4) .set_args(3, 4)
self.assertEqual(provider.args, tuple([3, 4])) self.assertEqual(provider.args, (3, 4))
def test_clear_args(self): def test_clear_args(self):
provider = providers.Resource(init_fn) \ provider = providers.Resource(init_fn) \

View File

@ -190,7 +190,7 @@ class _BaseSingletonTestCase(object):
provider = self.singleton_cls(Example) \ provider = self.singleton_cls(Example) \
.add_args(1, 2) \ .add_args(1, 2) \
.set_args(3, 4) .set_args(3, 4)
self.assertEqual(provider.args, tuple([3, 4])) self.assertEqual(provider.args, (3, 4))
def test_set_kwargs(self): def test_set_kwargs(self):
provider = self.singleton_cls(Example) \ provider = self.singleton_cls(Example) \

View File

@ -1,15 +1,10 @@
import contextlib
from decimal import Decimal from decimal import Decimal
import importlib
import unittest import unittest
from dependency_injector.wiring import ( from dependency_injector.wiring import (
wire, wire,
Provide, Provide,
Closing, Closing)
register_loader_containers,
unregister_loader_containers,
)
from dependency_injector import errors from dependency_injector import errors
# Runtime import to avoid syntax errors in samples on Python < 3.5 # Runtime import to avoid syntax errors in samples on Python < 3.5