mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-21 17:16:46 +03:00
Update quotes in the docs
This commit is contained in:
parent
023d766267
commit
98f036e14c
|
@ -19,7 +19,7 @@ additional arguments.
|
|||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
instance = concrete_factory()
|
||||
# Same as: # instance = SomeClass(base_argument=1, extra_argument=2)
|
||||
|
||||
|
@ -43,21 +43,21 @@ Passing of the arguments works the same way like for any other :ref:`factory-pro
|
|||
providers.Factory(dict, arg1=1),
|
||||
arg2=2,
|
||||
)
|
||||
print(chained_dict_factory()) # prints: {'arg1': 1, 'arg2': 2}
|
||||
print(chained_dict_factory()) # prints: {"arg1": 1, "arg2": 2}
|
||||
|
||||
# 2. Keyword arguments of upper level factory have priority
|
||||
chained_dict_factory = providers.Factory(
|
||||
providers.Factory(dict, arg1=1),
|
||||
arg1=2,
|
||||
)
|
||||
print(chained_dict_factory()) # prints: {'arg1': 2}
|
||||
print(chained_dict_factory()) # prints: {"arg1": 2}
|
||||
|
||||
# 3. Keyword arguments provided from context have the most priority
|
||||
chained_dict_factory = providers.Factory(
|
||||
providers.Factory(dict, arg1=1),
|
||||
arg1=2,
|
||||
)
|
||||
print(chained_dict_factory(arg1=3)) # prints: {'arg1': 3}
|
||||
print(chained_dict_factory(arg1=3)) # prints: {"arg1": 3}
|
||||
|
||||
|
||||
Credits
|
||||
|
|
|
@ -20,7 +20,7 @@ additional arguments.
|
|||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
instance = concrete_factory()
|
||||
# Same as: # instance = SomeClass(base_argument=1, extra_argument=2)
|
||||
|
||||
|
@ -46,7 +46,7 @@ Passing of the arguments works the same way like for any other :ref:`factory-pro
|
|||
arg1=1,
|
||||
)
|
||||
dict_factory = factory_of_dict_factories(arg2=2)
|
||||
print(dict_factory()) # prints: {'arg1': 1, 'arg2': 2}
|
||||
print(dict_factory()) # prints: {"arg1": 1, "arg2": 2}
|
||||
|
||||
# 2. Keyword arguments of upper level factory have priority
|
||||
factory_of_dict_factories = providers.Factory(
|
||||
|
@ -55,7 +55,7 @@ Passing of the arguments works the same way like for any other :ref:`factory-pro
|
|||
arg1=1,
|
||||
)
|
||||
dict_factory = factory_of_dict_factories(arg1=2)
|
||||
print(dict_factory()) # prints: {'arg1': 2}
|
||||
print(dict_factory()) # prints: {"arg1": 2}
|
||||
|
||||
# 3. Keyword arguments provided from context have the most priority
|
||||
factory_of_dict_factories = providers.Factory(
|
||||
|
@ -64,7 +64,7 @@ Passing of the arguments works the same way like for any other :ref:`factory-pro
|
|||
arg1=1,
|
||||
)
|
||||
dict_factory = factory_of_dict_factories(arg1=2)
|
||||
print(dict_factory(arg1=3)) # prints: {'arg1': 3}
|
||||
print(dict_factory(arg1=3)) # prints: {"arg1": 3}
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
|
|
@ -91,7 +91,7 @@ To use another loader use ``loader`` argument:
|
|||
import yaml
|
||||
|
||||
|
||||
container.config.from_yaml('config.yml', loader=yaml.UnsafeLoader)
|
||||
container.config.from_yaml("config.yml", loader=yaml.UnsafeLoader)
|
||||
|
||||
.. note::
|
||||
|
||||
|
@ -123,7 +123,7 @@ If you need to pass an argument to this call, use ``.from_pydantic()`` keyword a
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
container.config.from_pydantic(Settings(), exclude={'optional'})
|
||||
container.config.from_pydantic(Settings(), exclude={"optional"})
|
||||
|
||||
.. note::
|
||||
|
||||
|
@ -225,7 +225,7 @@ undefined environment variable that doesn't have a default value, pass argument
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
container.config.from_yaml('config.yml', envs_required=True)
|
||||
container.config.from_yaml("config.yml", envs_required=True)
|
||||
|
||||
See also: :ref:`configuration-strict-mode`.
|
||||
|
||||
|
@ -270,13 +270,13 @@ Mandatory YAML file:
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
container.config.from_yaml('config.yaml', required=True)
|
||||
container.config.from_yaml("config.yaml", required=True)
|
||||
|
||||
Mandatory INI file:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
container.config.from_ini('config.ini', required=True)
|
||||
container.config.from_ini("config.ini", required=True)
|
||||
|
||||
Mandatory dictionary:
|
||||
|
||||
|
@ -288,7 +288,7 @@ Mandatory environment variable:
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
container.config.api_key.from_env('API_KEY', required=True)
|
||||
container.config.api_key.from_env("API_KEY", required=True)
|
||||
|
||||
See also: :ref:`configuration-strict-mode`.
|
||||
|
||||
|
@ -346,16 +346,16 @@ configuration data is undefined:
|
|||
config = providers.Configuration(strict=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
container = Container()
|
||||
|
||||
try:
|
||||
container.config.from_yaml('does-not_exist.yml') # raise exception
|
||||
container.config.from_yaml("does-not_exist.yml") # raise exception
|
||||
except FileNotFoundError:
|
||||
...
|
||||
|
||||
try:
|
||||
container.config.from_ini('does-not_exist.ini') # raise exception
|
||||
container.config.from_ini("does-not_exist.ini") # raise exception
|
||||
except FileNotFoundError:
|
||||
...
|
||||
|
||||
|
@ -365,7 +365,7 @@ configuration data is undefined:
|
|||
...
|
||||
|
||||
try:
|
||||
container.config.from_env('UNDEFINED_ENV_VAR') # raise exception
|
||||
container.config.from_env("UNDEFINED_ENV_VAR") # raise exception
|
||||
except ValueError:
|
||||
...
|
||||
|
||||
|
@ -385,7 +385,7 @@ an undefined environment variable without a default value.
|
|||
.. code-block:: python
|
||||
|
||||
try:
|
||||
container.config.from_yaml('undefined_env.yml') # raise exception
|
||||
container.config.from_yaml("undefined_env.yml") # raise exception
|
||||
except ValueError:
|
||||
...
|
||||
|
||||
|
@ -398,11 +398,11 @@ You can override ``.from_*()`` methods behaviour in strict mode using ``required
|
|||
config = providers.Configuration(strict=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
container = Container()
|
||||
|
||||
container.config.from_yaml('config.yml')
|
||||
container.config.from_yaml('config.local.yml', required=False)
|
||||
container.config.from_yaml("config.yml")
|
||||
container.config.from_yaml("config.local.yml", required=False)
|
||||
|
||||
You can also use ``.required()`` option modifier when making an injection. It does not require to switch
|
||||
configuration provider to strict mode.
|
||||
|
|
|
@ -23,8 +23,8 @@ To use non-string keys or keys with ``.`` and ``-`` provide a dictionary as a po
|
|||
|
||||
providers.Dict({
|
||||
SomeClass: providers.Factory(...),
|
||||
'key.with.periods': providers.Factory(...),
|
||||
'key-with-dashes': providers.Factory(...),
|
||||
"key.with.periods": providers.Factory(...),
|
||||
"key-with-dashes": providers.Factory(...),
|
||||
})
|
||||
|
||||
Example:
|
||||
|
|
|
@ -30,7 +30,7 @@ IDE.
|
|||
provider = providers.Factory(Cat)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
animal = provider() # mypy knows that animal is of type "Cat"
|
||||
|
||||
|
||||
|
@ -54,5 +54,5 @@ function or method.
|
|||
provider: providers.Provider[Animal] = providers.Factory(Cat)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
animal = provider() # mypy knows that animal is of type "Animal"
|
||||
|
|
Loading…
Reference in New Issue
Block a user