Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uprev pydantic to v2.0a4 #55

Merged
merged 2 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def __init__(self, settings_cls: type[BaseSettings], init_kwargs: dict[str, Any]
super().__init__(settings_cls)

def get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str, bool]:
pass
# Nothing to do here. Only implement the return statement to make mypy happy
return None, '', False

def __call__(self) -> dict[str, Any]:
return self.init_kwargs
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ classifiers = [
]
requires-python = '>=3.7'
dependencies = [
'pydantic==v2.0a3',
'pydantic==v2.0a4',
'python-dotenv>=0.21.0',
]
dynamic = ['version']
Expand Down
1 change: 0 additions & 1 deletion requirements/linting.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ black
flake8
flake8-quotes
flake8-pyproject
hypothesis
isort
pyupgrade
mypy
Expand Down
48 changes: 20 additions & 28 deletions requirements/linting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,67 @@
#
# pip-compile --output-file=requirements/linting.txt requirements/linting.in
#
attrs==22.1.0
# via hypothesis
black==22.8.0
black==23.3.0
# via -r requirements/linting.in
cfgv==3.3.1
# via pre-commit
click==8.1.3
# via black
distlib==0.3.6
# via virtualenv
exceptiongroup==1.0.0rc9
# via hypothesis
filelock==3.8.0
filelock==3.12.0
# via virtualenv
flake8==5.0.4
flake8==6.0.0
# via
# -r requirements/linting.in
# flake8-pyproject
# flake8-quotes
flake8-pyproject==1.1.0.post0
flake8-pyproject==1.2.3
# via -r requirements/linting.in
flake8-quotes==3.3.1
flake8-quotes==3.3.2
# via -r requirements/linting.in
hypothesis==6.54.4
# via -r requirements/linting.in
identify==2.5.3
identify==2.5.24
# via pre-commit
isort==5.10.1
isort==5.12.0
# via -r requirements/linting.in
mccabe==0.7.0
# via flake8
mypy==0.971
mypy==1.3.0
# via -r requirements/linting.in
mypy-extensions==0.4.3
mypy-extensions==1.0.0
# via
# black
# mypy
nodeenv==1.7.0
nodeenv==1.8.0
# via pre-commit
pathspec==0.10.1
packaging==23.1
# via black
pathspec==0.11.1
# via black
platformdirs==2.5.2
platformdirs==3.5.1
# via
# black
# virtualenv
pre-commit==2.20.0
pre-commit==3.3.1
# via -r requirements/linting.in
pycodestyle==2.9.1
pycodestyle==2.10.0
# via flake8
pyflakes==2.5.0
pyflakes==3.0.1
# via flake8
pyupgrade==2.37.3
pyupgrade==3.4.0
# via -r requirements/linting.in
pyyaml==6.0
# via pre-commit
sortedcontainers==2.4.0
# via hypothesis
tokenize-rt==4.2.1
tokenize-rt==5.0.0
# via pyupgrade
toml==0.10.2
# via pre-commit
tomli==2.0.1
# via
# black
# flake8-pyproject
# mypy
typing-extensions==4.5.0
# via mypy
virtualenv==20.16.4
virtualenv==20.23.0
# via pre-commit

# The following packages are considered to be unsafe in a requirements file:
Expand Down
4 changes: 2 additions & 2 deletions requirements/pyproject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#
annotated-types==0.4.0
# via pydantic
pydantic==v2.0a3
pydantic==v2.0a4
# via pydantic-settings (pyproject.toml)
pydantic-core==0.25.0
pydantic-core==0.30.0
# via pydantic
python-dotenv==0.21.0
# via pydantic-settings (pyproject.toml)
Expand Down
26 changes: 11 additions & 15 deletions requirements/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,38 @@
#
# pip-compile --output-file=requirements/testing.txt requirements/testing.in
#
attrs==22.1.0
# via pytest
coverage[toml]==6.4.4
coverage[toml]==7.2.5
# via -r requirements/testing.in
importlib-metadata==4.12.0
exceptiongroup==1.1.1
# via pytest
importlib-metadata==6.6.0
# via
# pluggy
# pytest
iniconfig==1.1.1
iniconfig==2.0.0
# via pytest
packaging==21.3
packaging==23.1
# via
# pytest
# pytest-sugar
pluggy==1.0.0
# via pytest
py==1.11.0
# via pytest
pyparsing==3.0.9
# via packaging
pytest==7.1.3
pytest==7.3.1
# via
# -r requirements/testing.in
# pytest-mock
# pytest-sugar
pytest-mock==3.8.2
pytest-mock==3.10.0
# via -r requirements/testing.in
pytest-sugar==0.9.5
pytest-sugar==0.9.7
# via -r requirements/testing.in
termcolor==1.1.0
termcolor==2.3.0
# via pytest-sugar
tomli==2.0.1
# via
# coverage
# pytest
typing-extensions==4.5.0
# via importlib-metadata
zipp==3.8.1
zipp==3.15.0
# via importlib-metadata
28 changes: 18 additions & 10 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def test_sub_env_override(env):
def test_sub_env_missing():
with pytest.raises(ValidationError) as exc_info:
SimpleSettings()
assert exc_info.value.errors() == [{'type': 'missing', 'loc': ('apple',), 'msg': 'Field required', 'input': {}}]
assert exc_info.value.errors(include_url=False) == [
{'type': 'missing', 'loc': ('apple',), 'msg': 'Field required', 'input': {}}
]


def test_other_setting():
Expand Down Expand Up @@ -227,7 +229,7 @@ class AnnotatedComplexSettings(BaseSettings):
env.set('apples', '["russet"]')
with pytest.raises(ValidationError) as exc_info:
AnnotatedComplexSettings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'ctx': {'actual_length': 1, 'field_type': 'List', 'min_length': 2},
'input': ['russet'],
Expand Down Expand Up @@ -292,7 +294,7 @@ class ComplexSettings(BaseSettings):
env.set('field', '{"x": "a"}')
with pytest.raises(ValidationError) as exc_info:
ComplexSettings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'input': 'a',
'loc': ('field', 'x'),
Expand All @@ -318,7 +320,7 @@ class ComplexSettings(BaseSettings):
env.set('field', '{"x": "a"}')
with pytest.raises(ValidationError) as exc_info:
ComplexSettings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'input': 'a',
'loc': ('field', 'x'),
Expand All @@ -344,7 +346,7 @@ class ComplexSettings(BaseSettings):
env.set('field', '{"x": "a"}')
with pytest.raises(ValidationError) as exc_info:
ComplexSettings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'input': 'a',
'loc': ('field', 'x'),
Expand Down Expand Up @@ -507,7 +509,9 @@ class Settings(BaseSettings):
env.set('p_foo', 'bar')
with pytest.raises(ValidationError) as exc_info:
Settings()
assert exc_info.value.errors() == [{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}]
assert exc_info.value.errors(include_url=False) == [
{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}
]

env.set('foo', 'bar')
assert Settings().foobar == 'bar'
Expand All @@ -523,7 +527,9 @@ class Settings(BaseSettings):
monkeypatch.setattr(os, 'environ', value={'Foo': 'foo'})
with pytest.raises(ValidationError) as exc_info:
Settings()
assert exc_info.value.errors() == [{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}]
assert exc_info.value.errors(include_url=False) == [
{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}
]


def test_nested_dataclass(env):
Expand Down Expand Up @@ -684,7 +690,7 @@ class Settings(BaseSettings):

with pytest.raises(ValidationError) as exc_info:
Settings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'type': 'missing',
'loc': ('a',),
Expand Down Expand Up @@ -1127,7 +1133,9 @@ class Settings(BaseSettings):
with pytest.raises(ValidationError) as exc_info:
Settings()

assert exc_info.value.errors() == [{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}]
assert exc_info.value.errors(include_url=False) == [
{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}
]


def test_secrets_invalid_secrets_dir(tmp_path):
Expand Down Expand Up @@ -1546,7 +1554,7 @@ class Settings(BaseSettings):

with pytest.raises(ValidationError) as exc_info:
Settings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{'type': 'extra_forbidden', 'loc': ('x',), 'msg': 'Extra inputs are not permitted', 'input': 'y'}
]

Expand Down