From 320d837bea77fef1ed5d951db5c6fac834c9db93 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Thu, 30 Sep 2021 15:32:21 -0400 Subject: [PATCH] Update quotes in provider examples --- examples/providers/abstract_factory.py | 24 +++++++++---------- examples/providers/async.py | 4 ++-- examples/providers/async_overriding.py | 2 +- examples/providers/callable.py | 6 ++--- .../providers/configuration/configuration.py | 10 ++++---- .../configuration/configuration_alias.py | 12 +++++----- .../configuration/configuration_dict.py | 22 ++++++++--------- .../configuration/configuration_env.py | 18 +++++++------- ...figuration_env_interpolation_os_default.py | 8 +++---- .../configuration/configuration_ini.py | 18 +++++++------- .../configuration_itemselector.py | 20 ++++++++-------- .../configuration/configuration_multiple.py | 20 ++++++++-------- .../configuration/configuration_pydantic.py | 18 +++++++------- .../configuration/configuration_required.py | 2 +- .../configuration/configuration_strict.py | 2 +- .../configuration/configuration_type.py | 12 +++++----- .../configuration_type_custom.py | 8 +++---- .../configuration/configuration_value.py | 6 ++--- .../configuration/configuration_yaml.py | 18 +++++++------- examples/providers/coroutine.py | 2 +- examples/providers/custom_factory.py | 4 ++-- examples/providers/dependency.py | 2 +- examples/providers/dependency_default.py | 2 +- .../providers/dependency_undefined_error.py | 2 +- examples/providers/dict.py | 14 +++++------ examples/providers/dict_non_string_keys.py | 2 +- examples/providers/factory.py | 2 +- examples/providers/factory_aggregate.py | 6 ++--- .../providers/factory_attribute_injections.py | 2 +- examples/providers/factory_delegation.py | 4 ++-- examples/providers/factory_init_injections.py | 2 +- .../factory_init_injections_underlying.py | 2 +- examples/providers/factory_provided_type.py | 4 ++-- examples/providers/list.py | 14 +++++------ examples/providers/object.py | 2 +- examples/providers/overriding.py | 2 +- examples/providers/provided_instance.py | 6 ++--- .../providers/provided_instance_complex.py | 18 +++++++------- examples/providers/selector.py | 6 ++--- examples/providers/singleton.py | 2 +- .../providers/singleton_full_resetting.py | 2 +- .../singleton_multiple_containers.py | 2 +- examples/providers/singleton_resetting.py | 2 +- .../providers/singleton_resetting_with.py | 2 +- examples/providers/singleton_scoped.py | 6 ++--- examples/providers/singleton_thread_locals.py | 4 ++-- 46 files changed, 174 insertions(+), 174 deletions(-) diff --git a/examples/providers/abstract_factory.py b/examples/providers/abstract_factory.py index f67a66fb..ccdab3d5 100644 --- a/examples/providers/abstract_factory.py +++ b/examples/providers/abstract_factory.py @@ -41,26 +41,26 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() - cache_type = random.choice(['redis', 'memcached']) - if cache_type == 'redis': + cache_type = random.choice(["redis", "memcached"]) + if cache_type == "redis": container.cache_client_factory.override( providers.Factory( RedisCacheClient, - host='localhost', + host="localhost", port=6379, db=0, ), ) - elif cache_type == 'memcached': + elif cache_type == "memcached": container.cache_client_factory.override( providers.Factory( MemcachedCacheClient, - hosts=['10.0.1.1'], + hosts=["10.0.1.1"], port=11211, - prefix='my_app', + prefix="my_app", ), ) @@ -68,12 +68,12 @@ if __name__ == '__main__': print(service.cache) # The output depends on cache_type variable value. # - # If the value is 'redis': - # RedisCacheClient(host='localhost', port=6379, db=0) + # If the value is "redis": + # RedisCacheClient(host="localhost", port=6379, db=0) # - # If the value is 'memcached': - # MemcachedCacheClient(hosts=['10.0.1.1'], port=11211, prefix='my_app') + # If the value is "memcached": + # MemcachedCacheClient(hosts=["10.0.1.1"], port=11211, prefix="my_app") # # If the value is None: - # Error: AbstractFactory() must be + # Error: AbstractFactory() must be # overridden before calling diff --git a/examples/providers/async.py b/examples/providers/async.py index 297b3b2f..767d9263 100644 --- a/examples/providers/async.py +++ b/examples/providers/async.py @@ -7,7 +7,7 @@ from dependency_injector import containers, providers async def init_async_resource(): await asyncio.sleep(0.1) - yield 'Initialized' + yield "Initialized" class Service: @@ -31,7 +31,7 @@ async def main(container: Container): ... -if __name__ == '__main__': +if __name__ == "__main__": container = Container() asyncio.run(main(container)) diff --git a/examples/providers/async_overriding.py b/examples/providers/async_overriding.py index fc3ce320..ecd3c724 100644 --- a/examples/providers/async_overriding.py +++ b/examples/providers/async_overriding.py @@ -26,7 +26,7 @@ async def main(container: Container): ... -if __name__ == '__main__': +if __name__ == "__main__": container = Container() asyncio.run(main(container)) diff --git a/examples/providers/callable.py b/examples/providers/callable.py index 82d18e38..6cd39f9d 100644 --- a/examples/providers/callable.py +++ b/examples/providers/callable.py @@ -16,8 +16,8 @@ class Container(containers.DeclarativeContainer): password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() - hashed_password = container.password_hasher('super secret') - assert container.password_verifier('super secret', hashed_password) + hashed_password = container.password_hasher("super secret") + assert container.password_verifier("super secret", hashed_password) diff --git a/examples/providers/configuration/configuration.py b/examples/providers/configuration/configuration.py index 7a11cbfc..a596467e 100644 --- a/examples/providers/configuration/configuration.py +++ b/examples/providers/configuration/configuration.py @@ -10,19 +10,19 @@ class Container(containers.DeclarativeContainer): s3_client_factory = providers.Factory( boto3.client, - 's3', + "s3", aws_access_key_id=config.aws.access_key_id, aws_secret_access_key=config.aws.secret_access_key, ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() container.config.from_dict( { - 'aws': { - 'access_key_id': 'KEY', - 'secret_access_key': 'SECRET', + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", }, }, ) diff --git a/examples/providers/configuration/configuration_alias.py b/examples/providers/configuration/configuration_alias.py index 4cc02b7e..87b8b321 100644 --- a/examples/providers/configuration/configuration_alias.py +++ b/examples/providers/configuration/configuration_alias.py @@ -9,14 +9,14 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': +if __name__ == "__main__": env = Env() container = Container() with container.config.some_plugin_name as plugin: plugin.some_interval_ms.override( env.int( - 'SOME_INTERVAL_MS', + "SOME_INTERVAL_MS", default=30000, ), ) @@ -24,13 +24,13 @@ if __name__ == '__main__': with plugin.kafka as kafka: kafka.bootstrap_servers.override( env.list( - 'KAFKA_BOOTSTRAP_SERVERS', - default=['kafka1', 'kafka2'], + "KAFKA_BOOTSTRAP_SERVERS", + default=["kafka1", "kafka2"], ), ) kafka.security_protocol.override( env.str( - 'KAFKA_SECURITY_PROTOCOL', - default='SASL_SSL', + "KAFKA_SECURITY_PROTOCOL", + default="SASL_SSL", ), ) diff --git a/examples/providers/configuration/configuration_dict.py b/examples/providers/configuration/configuration_dict.py index d5669ccc..60154a96 100644 --- a/examples/providers/configuration/configuration_dict.py +++ b/examples/providers/configuration/configuration_dict.py @@ -8,27 +8,27 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': +if __name__ == "__main__": container = Container() container.config.from_dict( { - 'aws': { - 'access_key_id': 'KEY', - 'secret_access_key': 'SECRET', + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", }, }, ) assert container.config() == { - 'aws': { - 'access_key_id': 'KEY', - 'secret_access_key': 'SECRET', + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", }, } assert container.config.aws() == { - 'access_key_id': 'KEY', - 'secret_access_key': 'SECRET', + "access_key_id": "KEY", + "secret_access_key": "SECRET", } - assert container.config.aws.access_key_id() == 'KEY' - assert container.config.aws.secret_access_key() == 'SECRET' + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET" diff --git a/examples/providers/configuration/configuration_env.py b/examples/providers/configuration/configuration_env.py index b9d491bc..98a579a9 100644 --- a/examples/providers/configuration/configuration_env.py +++ b/examples/providers/configuration/configuration_env.py @@ -10,17 +10,17 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': +if __name__ == "__main__": container = Container() # Emulate environment variables - os.environ['AWS_ACCESS_KEY_ID'] = 'KEY' - os.environ['AWS_SECRET_ACCESS_KEY'] = 'SECRET' + os.environ["AWS_ACCESS_KEY_ID"] = "KEY" + os.environ["AWS_SECRET_ACCESS_KEY"] = "SECRET" - container.config.aws.access_key_id.from_env('AWS_ACCESS_KEY_ID') - container.config.aws.secret_access_key.from_env('AWS_SECRET_ACCESS_KEY') - container.config.optional.from_env('UNDEFINED', 'default_value') + container.config.aws.access_key_id.from_env("AWS_ACCESS_KEY_ID") + container.config.aws.secret_access_key.from_env("AWS_SECRET_ACCESS_KEY") + container.config.optional.from_env("UNDEFINED", "default_value") - assert container.config.aws.access_key_id() == 'KEY' - assert container.config.aws.secret_access_key() == 'SECRET' - assert container.config.optional() == 'default_value' + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET" + assert container.config.optional() == "default_value" diff --git a/examples/providers/configuration/configuration_env_interpolation_os_default.py b/examples/providers/configuration/configuration_env_interpolation_os_default.py index 527192ac..e033cc88 100644 --- a/examples/providers/configuration/configuration_env_interpolation_os_default.py +++ b/examples/providers/configuration/configuration_env_interpolation_os_default.py @@ -10,10 +10,10 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': - os.environ.setdefault('ENV_VAR', 'default value') +if __name__ == "__main__": + os.environ.setdefault("ENV_VAR", "default value") container = Container() - container.config.from_yaml('config-with-env-var.yml') + container.config.from_yaml("config-with-env-var.yml") - assert container.config.section.option() == 'default value' + assert container.config.section.option() == "default value" diff --git a/examples/providers/configuration/configuration_ini.py b/examples/providers/configuration/configuration_ini.py index 98783bd0..21fdc994 100644 --- a/examples/providers/configuration/configuration_ini.py +++ b/examples/providers/configuration/configuration_ini.py @@ -8,20 +8,20 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': +if __name__ == "__main__": container = Container() - container.config.from_ini('examples/providers/configuration/config.ini') + container.config.from_ini("./config.ini") assert container.config() == { - 'aws': { - 'access_key_id': 'KEY', - 'secret_access_key': 'SECRET', + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", }, } assert container.config.aws() == { - 'access_key_id': 'KEY', - 'secret_access_key': 'SECRET', + "access_key_id": "KEY", + "secret_access_key": "SECRET", } - assert container.config.aws.access_key_id() == 'KEY' - assert container.config.aws.secret_access_key() == 'SECRET' + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET" diff --git a/examples/providers/configuration/configuration_itemselector.py b/examples/providers/configuration/configuration_itemselector.py index eb257843..11addb8e 100644 --- a/examples/providers/configuration/configuration_itemselector.py +++ b/examples/providers/configuration/configuration_itemselector.py @@ -14,15 +14,15 @@ class Foo: class Container(containers.DeclarativeContainer): config = providers.Configuration(default={ - 'target': 'A', - 'items': { - 'A': { - 'option1': 60, - 'option2': 80, + "target": "A", + "items": { + "A": { + "option1": 60, + "option2": 80, }, - 'B': { - 'option1': 10, - 'option2': 20, + "B": { + "option1": 10, + "option2": 20, }, }, }) @@ -34,10 +34,10 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() - container.config.target.from_env('TARGET') + container.config.target.from_env("TARGET") foo = container.foo_factory() print(foo.option1, foo.option2) diff --git a/examples/providers/configuration/configuration_multiple.py b/examples/providers/configuration/configuration_multiple.py index ac95b3e2..907f82e5 100644 --- a/examples/providers/configuration/configuration_multiple.py +++ b/examples/providers/configuration/configuration_multiple.py @@ -8,21 +8,21 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': +if __name__ == "__main__": container = Container() - container.config.from_yaml('examples/providers/configuration/config.yml') - container.config.from_yaml('examples/providers/configuration/config.local.yml') + container.config.from_yaml("./config.yml") + container.config.from_yaml("./config.local.yml") assert container.config() == { - 'aws': { - 'access_key_id': 'LOCAL-KEY', - 'secret_access_key': 'LOCAL-SECRET', + "aws": { + "access_key_id": "LOCAL-KEY", + "secret_access_key": "LOCAL-SECRET", }, } assert container.config.aws() == { - 'access_key_id': 'LOCAL-KEY', - 'secret_access_key': 'LOCAL-SECRET', + "access_key_id": "LOCAL-KEY", + "secret_access_key": "LOCAL-SECRET", } - assert container.config.aws.access_key_id() == 'LOCAL-KEY' - assert container.config.aws.secret_access_key() == 'LOCAL-SECRET' + assert container.config.aws.access_key_id() == "LOCAL-KEY" + assert container.config.aws.secret_access_key() == "LOCAL-SECRET" diff --git a/examples/providers/configuration/configuration_pydantic.py b/examples/providers/configuration/configuration_pydantic.py index 7dd20460..aaed5d26 100644 --- a/examples/providers/configuration/configuration_pydantic.py +++ b/examples/providers/configuration/configuration_pydantic.py @@ -6,20 +6,20 @@ from dependency_injector import containers, providers from pydantic import BaseSettings, Field # Emulate environment variables -os.environ['AWS_ACCESS_KEY_ID'] = 'KEY' -os.environ['AWS_SECRET_ACCESS_KEY'] = 'SECRET' +os.environ["AWS_ACCESS_KEY_ID"] = "KEY" +os.environ["AWS_SECRET_ACCESS_KEY"] = "SECRET" class AwsSettings(BaseSettings): - access_key_id: str = Field(env='aws_access_key_id') - secret_access_key: str = Field(env='aws_secret_access_key') + access_key_id: str = Field(env="aws_access_key_id") + secret_access_key: str = Field(env="aws_secret_access_key") class Settings(BaseSettings): aws: AwsSettings = AwsSettings() - optional: str = Field(default='default_value') + optional: str = Field(default="default_value") class Container(containers.DeclarativeContainer): @@ -27,11 +27,11 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': +if __name__ == "__main__": container = Container() container.config.from_pydantic(Settings()) - assert container.config.aws.access_key_id() == 'KEY' - assert container.config.aws.secret_access_key() == 'SECRET' - assert container.config.optional() == 'default_value' + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET" + assert container.config.optional() == "default_value" diff --git a/examples/providers/configuration/configuration_required.py b/examples/providers/configuration/configuration_required.py index 6e77f27f..54c91932 100644 --- a/examples/providers/configuration/configuration_required.py +++ b/examples/providers/configuration/configuration_required.py @@ -20,7 +20,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() try: diff --git a/examples/providers/configuration/configuration_strict.py b/examples/providers/configuration/configuration_strict.py index 3922f450..74868a07 100644 --- a/examples/providers/configuration/configuration_strict.py +++ b/examples/providers/configuration/configuration_strict.py @@ -20,7 +20,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() try: diff --git a/examples/providers/configuration/configuration_type.py b/examples/providers/configuration/configuration_type.py index 8c8e044d..407a3597 100644 --- a/examples/providers/configuration/configuration_type.py +++ b/examples/providers/configuration/configuration_type.py @@ -22,17 +22,17 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() # Emulate environment variables - os.environ['API_KEY'] = 'secret' - os.environ['API_TIMEOUT'] = '5' + os.environ["API_KEY"] = "secret" + os.environ["API_TIMEOUT"] = "5" - container.config.api.key.from_env('API_KEY') - container.config.api.timeout.from_env('API_TIMEOUT') + container.config.api.key.from_env("API_KEY") + container.config.api.timeout.from_env("API_TIMEOUT") api_client = container.api_client_factory() - assert api_client.api_key == 'secret' + assert api_client.api_key == "secret" assert api_client.timeout == 5 diff --git a/examples/providers/configuration/configuration_type_custom.py b/examples/providers/configuration/configuration_type_custom.py index 6782ab52..cac285a0 100644 --- a/examples/providers/configuration/configuration_type_custom.py +++ b/examples/providers/configuration/configuration_type_custom.py @@ -21,14 +21,14 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() # Emulate environment variables - os.environ['PI'] = '3.1415926535897932384626433832' + os.environ["PI"] = "3.1415926535897932384626433832" - container.config.pi.from_env('PI') + container.config.pi.from_env("PI") calculator = container.calculator_factory() - assert calculator.pi == decimal.Decimal('3.1415926535897932384626433832') + assert calculator.pi == decimal.Decimal("3.1415926535897932384626433832") diff --git a/examples/providers/configuration/configuration_value.py b/examples/providers/configuration/configuration_value.py index 3e9c3125..456af119 100644 --- a/examples/providers/configuration/configuration_value.py +++ b/examples/providers/configuration/configuration_value.py @@ -10,15 +10,15 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': +if __name__ == "__main__": container = Container() container.config.option1.from_value(date(2021, 6, 13)) container.config.option2.from_value(date(2021, 6, 14)) assert container.config() == { - 'option1': date(2021, 6, 13), - 'option2': date(2021, 6, 14), + "option1": date(2021, 6, 13), + "option2": date(2021, 6, 14), } assert container.config.option1() == date(2021, 6, 13) assert container.config.option2() == date(2021, 6, 14) diff --git a/examples/providers/configuration/configuration_yaml.py b/examples/providers/configuration/configuration_yaml.py index d281aaf0..a347a296 100644 --- a/examples/providers/configuration/configuration_yaml.py +++ b/examples/providers/configuration/configuration_yaml.py @@ -8,20 +8,20 @@ class Container(containers.DeclarativeContainer): config = providers.Configuration() -if __name__ == '__main__': +if __name__ == "__main__": container = Container() - container.config.from_yaml('examples/providers/configuration/config.yml') + container.config.from_yaml("./config.yml") assert container.config() == { - 'aws': { - 'access_key_id': 'KEY', - 'secret_access_key': 'SECRET', + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", }, } assert container.config.aws() == { - 'access_key_id': 'KEY', - 'secret_access_key': 'SECRET', + "access_key_id": "KEY", + "secret_access_key": "SECRET", } - assert container.config.aws.access_key_id() == 'KEY' - assert container.config.aws.secret_access_key() == 'SECRET' + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET" diff --git a/examples/providers/coroutine.py b/examples/providers/coroutine.py index d42689ba..a6009b45 100644 --- a/examples/providers/coroutine.py +++ b/examples/providers/coroutine.py @@ -15,7 +15,7 @@ class Container(containers.DeclarativeContainer): coroutine_provider = providers.Coroutine(coroutine, arg1=1, arg2=2) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() arg1, arg2 = asyncio.run(container.coroutine_provider()) diff --git a/examples/providers/custom_factory.py b/examples/providers/custom_factory.py index 159e93af..bd0c17f1 100644 --- a/examples/providers/custom_factory.py +++ b/examples/providers/custom_factory.py @@ -5,7 +5,7 @@ from dependency_injector import containers, providers class CustomFactory(providers.Provider): - __slots__ = ('_factory',) + __slots__ = ("_factory",) def __init__(self, provides, *args, **kwargs): self._factory = providers.Factory(provides, *args, **kwargs) @@ -40,7 +40,7 @@ class Container(containers.DeclarativeContainer): factory = CustomFactory(object) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() object1 = container.factory() diff --git a/examples/providers/dependency.py b/examples/providers/dependency.py index c1b7b03f..e53b6dc4 100644 --- a/examples/providers/dependency.py +++ b/examples/providers/dependency.py @@ -33,7 +33,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container1 = Container(database=providers.Singleton(SqliteDbAdapter)) container2 = Container(database=providers.Singleton(PostgresDbAdapter)) diff --git a/examples/providers/dependency_default.py b/examples/providers/dependency_default.py index 756229df..ad06dc11 100644 --- a/examples/providers/dependency_default.py +++ b/examples/providers/dependency_default.py @@ -18,7 +18,7 @@ class Container(containers.DeclarativeContainer): cache = providers.Dependency(instance_of=Cache, default=InMemoryCache()) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() cache = container.cache() # provides InMemoryCache() diff --git a/examples/providers/dependency_undefined_error.py b/examples/providers/dependency_undefined_error.py index d7ee2cbc..60684f00 100644 --- a/examples/providers/dependency_undefined_error.py +++ b/examples/providers/dependency_undefined_error.py @@ -25,7 +25,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() container.user_service() # <-- raises error: # Dependency "Container.database" is not defined diff --git a/examples/providers/dict.py b/examples/providers/dict.py index 75f1a51e..871c1871 100644 --- a/examples/providers/dict.py +++ b/examples/providers/dict.py @@ -21,25 +21,25 @@ class Container(containers.DeclarativeContainer): dispatcher_factory = providers.Factory( Dispatcher, modules=providers.Dict( - module1=providers.Factory(Module, name='m1'), - module2=providers.Factory(Module, name='m2'), + module1=providers.Factory(Module, name="m1"), + module2=providers.Factory(Module, name="m2"), ), ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() dispatcher = container.dispatcher_factory() assert isinstance(dispatcher.modules, dict) - assert dispatcher.modules['module1'].name == 'm1' - assert dispatcher.modules['module2'].name == 'm2' + assert dispatcher.modules["module1"].name == "m1" + assert dispatcher.modules["module2"].name == "m2" # Call "dispatcher = container.dispatcher_factory()" is equivalent to: # dispatcher = Dispatcher( # modules={ - # 'module1': Module(name='m1'), - # 'module2': Module(name='m2'), + # "module1": Module(name="m1"), + # "module2": Module(name="m2"), # }, # ) diff --git a/examples/providers/dict_non_string_keys.py b/examples/providers/dict_non_string_keys.py index 11c7a593..52982078 100644 --- a/examples/providers/dict_non_string_keys.py +++ b/examples/providers/dict_non_string_keys.py @@ -46,7 +46,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() dispatcher = container.dispatcher_factory() diff --git a/examples/providers/factory.py b/examples/providers/factory.py index 7fa38386..65d1ccf3 100644 --- a/examples/providers/factory.py +++ b/examples/providers/factory.py @@ -12,7 +12,7 @@ class Container(containers.DeclarativeContainer): user_factory = providers.Factory(User) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() user1 = container.user_factory() diff --git a/examples/providers/factory_aggregate.py b/examples/providers/factory_aggregate.py index 299e17cc..a8775274 100644 --- a/examples/providers/factory_aggregate.py +++ b/examples/providers/factory_aggregate.py @@ -13,8 +13,8 @@ class Game: def play(self): print( - f'{self.player1} and {self.player2} are ' - f'playing {self.__class__.__name__.lower()}' + f"{self.player1} and {self.player2} are " + f"playing {self.__class__.__name__.lower()}" ) @@ -39,7 +39,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": game_type = sys.argv[1].lower() player1 = sys.argv[2].capitalize() player2 = sys.argv[3].capitalize() diff --git a/examples/providers/factory_attribute_injections.py b/examples/providers/factory_attribute_injections.py index f2d83e4b..ea242316 100644 --- a/examples/providers/factory_attribute_injections.py +++ b/examples/providers/factory_attribute_injections.py @@ -20,7 +20,7 @@ class Container(containers.DeclarativeContainer): service.add_attributes(client=client) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() service = container.service() diff --git a/examples/providers/factory_delegation.py b/examples/providers/factory_delegation.py index 7112ab3a..3e64129d 100644 --- a/examples/providers/factory_delegation.py +++ b/examples/providers/factory_delegation.py @@ -17,7 +17,7 @@ class UserRepository: def get_all(self) -> List[User]: return [ self.user_factory(**user_data) - for user_data in [{'uid': 1}, {'uid': 2}] + for user_data in [{"uid": 1}, {"uid": 2}] ] @@ -31,7 +31,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() user_repository = container.user_repository_factory() diff --git a/examples/providers/factory_init_injections.py b/examples/providers/factory_init_injections.py index 134d5b16..ec035a93 100644 --- a/examples/providers/factory_init_injections.py +++ b/examples/providers/factory_init_injections.py @@ -23,7 +23,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() user1 = container.user_factory(1) diff --git a/examples/providers/factory_init_injections_underlying.py b/examples/providers/factory_init_injections_underlying.py index cc291a6a..de1130f3 100644 --- a/examples/providers/factory_init_injections_underlying.py +++ b/examples/providers/factory_init_injections_underlying.py @@ -39,7 +39,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() algorithm_1 = container.algorithm_factory( diff --git a/examples/providers/factory_provided_type.py b/examples/providers/factory_provided_type.py index bcf80b71..c750028f 100644 --- a/examples/providers/factory_provided_type.py +++ b/examples/providers/factory_provided_type.py @@ -29,5 +29,5 @@ try: except errors.Error as exception: print(exception) # The output is: - # can provide only - # instances + # can provide only + # instances diff --git a/examples/providers/list.py b/examples/providers/list.py index d7096e62..254f3a3c 100644 --- a/examples/providers/list.py +++ b/examples/providers/list.py @@ -21,25 +21,25 @@ class Container(containers.DeclarativeContainer): dispatcher_factory = providers.Factory( Dispatcher, modules=providers.List( - providers.Factory(Module, name='m1'), - providers.Factory(Module, name='m2'), + providers.Factory(Module, name="m1"), + providers.Factory(Module, name="m2"), ), ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() dispatcher = container.dispatcher_factory() assert isinstance(dispatcher.modules, list) - assert dispatcher.modules[0].name == 'm1' - assert dispatcher.modules[1].name == 'm2' + assert dispatcher.modules[0].name == "m1" + assert dispatcher.modules[1].name == "m2" # Call "dispatcher = container.dispatcher_factory()" is equivalent to: # dispatcher = Dispatcher( # modules=[ - # Module(name='m1'), - # Module(name='m2'), + # Module(name="m1"), + # Module(name="m2"), # ], # ) diff --git a/examples/providers/object.py b/examples/providers/object.py index d0066153..9a635e2d 100644 --- a/examples/providers/object.py +++ b/examples/providers/object.py @@ -8,7 +8,7 @@ class Container(containers.DeclarativeContainer): object_provider = providers.Object(1) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() assert container.object_provider() == 1 diff --git a/examples/providers/overriding.py b/examples/providers/overriding.py index 9627667c..ca2868c1 100644 --- a/examples/providers/overriding.py +++ b/examples/providers/overriding.py @@ -29,7 +29,7 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() # 1. Use .override() to replace the API client with stub diff --git a/examples/providers/provided_instance.py b/examples/providers/provided_instance.py index bf63bc6f..46416e48 100644 --- a/examples/providers/provided_instance.py +++ b/examples/providers/provided_instance.py @@ -5,7 +5,7 @@ from dependency_injector import containers, providers class Service: def __init__(self): - self.value = 'foo' + self.value = "foo" self.values = [self.value] def get_value(self): @@ -36,8 +36,8 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() client = container.client_factory() - assert client.value1 == client.value2 == client.value3 == 'foo' + assert client.value1 == client.value2 == client.value3 == "foo" diff --git a/examples/providers/provided_instance_complex.py b/examples/providers/provided_instance_complex.py index 108e1ebf..5a2d42d4 100644 --- a/examples/providers/provided_instance_complex.py +++ b/examples/providers/provided_instance_complex.py @@ -18,23 +18,23 @@ class Container(containers.DeclarativeContainer): dependency = providers.Object( { - 'foo': { - 'bar': 10, - 'baz': lambda arg: {'arg': arg} + "foo": { + "bar": 10, + "baz": lambda arg: {"arg": arg} }, }, ) demo_list = providers.List( - dependency.provided['foo']['bar'], - dependency.provided['foo']['baz'].call(22)['arg'], - dependency.provided['foo']['baz'].call(service)['arg'], - dependency.provided['foo']['baz'].call(service)['arg'].value, - dependency.provided['foo']['baz'].call(service)['arg'].get_value.call(), + dependency.provided["foo"]["bar"], + dependency.provided["foo"]["baz"].call(22)["arg"], + dependency.provided["foo"]["baz"].call(service)["arg"], + dependency.provided["foo"]["baz"].call(service)["arg"].value, + dependency.provided["foo"]["baz"].call(service)["arg"].get_value.call(), ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() assert container.demo_list() == [ diff --git a/examples/providers/selector.py b/examples/providers/selector.py index 88166ec4..4ab232bc 100644 --- a/examples/providers/selector.py +++ b/examples/providers/selector.py @@ -22,13 +22,13 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() - container.config.override({'one_or_another': 'one'}) + container.config.override({"one_or_another": "one"}) instance_1 = container.selector() assert isinstance(instance_1, SomeClass) - container.config.override({'one_or_another': 'another'}) + container.config.override({"one_or_another": "another"}) instance_2 = container.selector() assert isinstance(instance_2, SomeOtherClass) diff --git a/examples/providers/singleton.py b/examples/providers/singleton.py index f1083895..d8842a29 100644 --- a/examples/providers/singleton.py +++ b/examples/providers/singleton.py @@ -12,7 +12,7 @@ class Container(containers.DeclarativeContainer): user_service_provider = providers.Singleton(UserService) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() user_service1 = container.user_service_provider() diff --git a/examples/providers/singleton_full_resetting.py b/examples/providers/singleton_full_resetting.py index e3394c8c..512b2073 100644 --- a/examples/providers/singleton_full_resetting.py +++ b/examples/providers/singleton_full_resetting.py @@ -19,7 +19,7 @@ class Container(containers.DeclarativeContainer): user_service = providers.Singleton(UserService, db=database) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() user_service1 = container.user_service() diff --git a/examples/providers/singleton_multiple_containers.py b/examples/providers/singleton_multiple_containers.py index 7b5e4fab..40f5fb1b 100644 --- a/examples/providers/singleton_multiple_containers.py +++ b/examples/providers/singleton_multiple_containers.py @@ -12,7 +12,7 @@ class Container(containers.DeclarativeContainer): user_service_provider = providers.Singleton(UserService) -if __name__ == '__main__': +if __name__ == "__main__": container1 = Container() user_service1 = container1.user_service_provider() assert user_service1 is container1.user_service_provider() diff --git a/examples/providers/singleton_resetting.py b/examples/providers/singleton_resetting.py index a436f188..faa1cf81 100644 --- a/examples/providers/singleton_resetting.py +++ b/examples/providers/singleton_resetting.py @@ -12,7 +12,7 @@ class Container(containers.DeclarativeContainer): user_service = providers.Singleton(UserService) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() user_service1 = container.user_service() diff --git a/examples/providers/singleton_resetting_with.py b/examples/providers/singleton_resetting_with.py index fe52996b..37ecaa66 100644 --- a/examples/providers/singleton_resetting_with.py +++ b/examples/providers/singleton_resetting_with.py @@ -12,7 +12,7 @@ class Container(containers.DeclarativeContainer): user_service = providers.Singleton(UserService) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() user_service1 = container.user_service() diff --git a/examples/providers/singleton_scoped.py b/examples/providers/singleton_scoped.py index a07c74e5..597bda29 100644 --- a/examples/providers/singleton_scoped.py +++ b/examples/providers/singleton_scoped.py @@ -18,7 +18,7 @@ def index_view(): service_2 = current_app.container.service_provider() assert service_1 is service_2 print(service_1) - return 'Hello World!' + return "Hello World!" def teardown_context(request): @@ -30,9 +30,9 @@ container = Container() app = Flask(__name__) app.container = container -app.add_url_rule('/', 'index', view_func=index_view) +app.add_url_rule("/", "index", view_func=index_view) app.after_request(teardown_context) -if __name__ == '__main__': +if __name__ == "__main__": app.run() diff --git a/examples/providers/singleton_thread_locals.py b/examples/providers/singleton_thread_locals.py index 1255d718..2b51b1d2 100644 --- a/examples/providers/singleton_thread_locals.py +++ b/examples/providers/singleton_thread_locals.py @@ -28,14 +28,14 @@ class Container(containers.DeclarativeContainer): ) -if __name__ == '__main__': +if __name__ == "__main__": container = Container() n = 10 threads = [] for thread_number in range(n): threads.append( - container.thread_factory(name='Thread{0}'.format(thread_number)), + container.thread_factory(name="Thread{0}".format(thread_number)), ) for thread in threads: thread.start()