File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed
pydantic_settings/sources Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ def parse_env_vars(
43
43
def _annotation_is_complex (annotation : type [Any ] | None , metadata : list [Any ]) -> bool :
44
44
# If the model is a root model, the root annotation should be used to
45
45
# evaluate the complexity.
46
+ if annotation and (
47
+ typing_objects .is_typealiastype (annotation ) or typing_objects .is_typealiastype (get_origin (annotation ))
48
+ ):
49
+ annotation = annotation .__value__
46
50
if annotation is not None and _lenient_issubclass (annotation , RootModel ) and annotation is not RootModel :
47
51
annotation = cast ('type[RootModel[Any]]' , annotation )
48
52
root_annotation = annotation .model_fields ['root' ].annotation
Original file line number Diff line number Diff line change @@ -143,6 +143,9 @@ pydocstyle = { convention = 'google' }
143
143
[tool .ruff .format ]
144
144
quote-style = ' single'
145
145
146
+ [tool .ruff .per-file-target-version ]
147
+ "tests/test_settings_py312.py" = " py312"
148
+
146
149
[tool .mypy ]
147
150
python_version = ' 3.10'
148
151
show_error_codes = true
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import os
4
+ import sys
4
5
from pathlib import Path
5
6
from typing import TYPE_CHECKING
6
7
@@ -99,3 +100,20 @@ def cli_test_env():
99
100
yield setenv
100
101
101
102
setenv .clear ()
103
+
104
+
105
+ def pytest_ignore_collect (collection_path : Path , config ) -> bool :
106
+ """
107
+ Ignore collection of test files that contain syntax unsupported
108
+ by the current Python version.
109
+ """
110
+ py312_tests = {'test_settings_py312.py' }
111
+
112
+ if sys .version_info < (3 , 12 ) and collection_path .name in py312_tests :
113
+ print (
114
+ f"\n Skipping collection of '{ collection_path .name } ' on Python "
115
+ f'{ sys .version_info .major } .{ sys .version_info .minor } due to syntax requirements.'
116
+ )
117
+ return True
118
+
119
+ return None
Original file line number Diff line number Diff line change
1
+ from typing import Annotated
2
+
3
+ from annotated_types import MinLen
4
+
5
+ from pydantic_settings import BaseSettings
6
+
7
+ try :
8
+ import dotenv
9
+ except ImportError :
10
+ dotenv = None
11
+
12
+
13
+ def test_annotated_with_type (env ):
14
+ type MinLenList = Annotated [list [str ], MinLen (2 )]
15
+
16
+ class AnnotatedComplexSettings (BaseSettings ):
17
+ apples : MinLenList
18
+
19
+ env .set ('apples' , '["russet", "granny smith"]' )
20
+ s = AnnotatedComplexSettings ()
21
+ assert s .apples == ['russet' , 'granny smith' ]
You can’t perform that action at this time.
0 commit comments