Skip to content

Commit 2789ef2

Browse files
committed
Fixed some usages in documentation and tests
1 parent 352a2db commit 2789ef2

File tree

7 files changed

+23
-18
lines changed

7 files changed

+23
-18
lines changed

docs/providers/configuration.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,22 @@ See also: :ref:`configuration-envs-interpolation`.
183183
Loading from a Pydantic settings
184184
--------------------------------
185185

186-
``Configuration`` provider can load configuration from a ``pydantic`` settings object using the
186+
``Configuration`` provider can load configuration from a ``pydantic-settings`` Settings object using the
187187
:py:meth:`Configuration.from_pydantic` method:
188188

189189
.. literalinclude:: ../../examples/providers/configuration/configuration_pydantic.py
190190
:language: python
191191
:lines: 3-
192192
:emphasize-lines: 31
193193

194-
To get the data from pydantic settings ``Configuration`` provider calls ``Settings.dict()`` method.
194+
To get the data from pydantic settings ``Configuration`` provider calls ``Settings.model_dump()`` method.
195195
If you need to pass an argument to this call, use ``.from_pydantic()`` keyword arguments.
196196

197197
.. code-block:: python
198198
199199
container.config.from_pydantic(Settings(), exclude={"optional"})
200200
201-
Alternatively, you can provide a ``pydantic`` settings object over the configuration provider argument. In that case,
201+
Alternatively, you can provide a ``pydantic-settings`` Settings object over the configuration provider argument. In that case,
202202
the container will call ``config.from_pydantic()`` automatically:
203203

204204
.. code-block:: python
@@ -215,15 +215,15 @@ the container will call ``config.from_pydantic()`` automatically:
215215
216216
.. note::
217217

218-
``Dependency Injector`` doesn't install ``pydantic`` by default.
218+
``Dependency Injector`` doesn't install ``pydantic-settings`` by default.
219219

220220
You can install the ``Dependency Injector`` with an extra dependency::
221221

222-
pip install dependency-injector[pydantic]
222+
pip install dependency-injector[pydantic-settings]
223223

224-
or install ``pydantic`` directly::
224+
or install ``pydantic-settings`` directly::
225225

226-
pip install pydantic
226+
pip install pydantic-settings
227227

228228
*Don't forget to mirror the changes in the requirements file.*
229229

examples/providers/configuration/configuration_pydantic.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import os
44

5+
from typing import Annotated
6+
57
from dependency_injector import containers, providers
6-
from pydantic import BaseSettings, Field
8+
from pydantic import Field
9+
from pydantic_settings import BaseSettings
710

811
# Emulate environment variables
912
os.environ["AWS_ACCESS_KEY_ID"] = "KEY"
@@ -12,8 +15,8 @@
1215

1316
class AwsSettings(BaseSettings):
1417

15-
access_key_id: str = Field(env="aws_access_key_id")
16-
secret_access_key: str = Field(env="aws_secret_access_key")
18+
access_key_id: str = Field(alias="aws_access_key_id")
19+
secret_access_key: str = Field(alias="aws_secret_access_key")
1720

1821

1922
class Settings(BaseSettings):

examples/providers/configuration/configuration_pydantic_init.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44

55
from dependency_injector import containers, providers
6-
from pydantic import BaseSettings, Field
6+
from pydantic import Field
7+
from pydantic_settings import BaseSettings
78

89
# Emulate environment variables
910
os.environ["AWS_ACCESS_KEY_ID"] = "KEY"
@@ -12,8 +13,8 @@
1213

1314
class AwsSettings(BaseSettings):
1415

15-
access_key_id: str = Field(env="aws_access_key_id")
16-
secret_access_key: str = Field(env="aws_secret_access_key")
16+
access_key_id: str = Field(alias="aws_access_key_id")
17+
secret_access_key: str = Field(alias="aws_secret_access_key")
1718

1819

1920
class Settings(BaseSettings):

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mypy
1111
pyyaml
1212
httpx
1313
fastapi
14-
pydantic
14+
pydantic-settings
1515
numpy
1616
scipy
1717
boto3

tests/typing/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22

33
from dependency_injector import providers
4-
from pydantic import BaseSettings as PydanticSettings
4+
from pydantic_settings import BaseSettings as PydanticSettings
55

66

77
# Test 1: to check the getattr

tests/unit/providers/configuration/test_from_pydantic_py36.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Configuration.from_pydantic() tests."""
22

33
import pydantic
4+
import pydantic_settings
45
from dependency_injector import providers, errors
56
from pytest import fixture, mark, raises
67

@@ -13,7 +14,7 @@ class Section12(pydantic.BaseModel):
1314
value2 = 2
1415

1516

16-
class Settings1(pydantic.BaseSettings):
17+
class Settings1(pydantic_settings.BaseSettings):
1718
section1 = Section11()
1819
section2 = Section12()
1920

@@ -27,7 +28,7 @@ class Section3(pydantic.BaseModel):
2728
value3 = 3
2829

2930

30-
class Settings2(pydantic.BaseSettings):
31+
class Settings2(pydantic_settings.BaseSettings):
3132
section1 = Section21()
3233
section3 = Section3()
3334

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ deps=
1616
mypy_boto3_s3
1717
extras=
1818
yaml
19-
pydantic
19+
pydantic-settings
2020
flask
2121
aiohttp
2222
commands = pytest -c tests/.configs/pytest.ini

0 commit comments

Comments
 (0)