Skip to content

Commit

Permalink
More Python 3.8 and 3.9 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kschwab committed Jan 29, 2024
1 parent ff5b7ed commit 7ea4c97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,9 @@ def _union_is_complex(annotation: type[Any] | None, metadata: list[Any]) -> bool


def _annotation_contains_types(annotation: type[Any] | None, types: tuple[Any, ...]) -> bool:
if origin_is_union(get_origin(annotation)) or isinstance(annotation, WithArgsTypes):
if get_origin(annotation) in types:
if get_origin(annotation) in types:
return True
for type_ in get_args(annotation):
if _annotation_contains_types(type_, types):
return True
for type_ in get_args(annotation):
if _annotation_contains_types(type_, types):
return True
return annotation in types
8 changes: 4 additions & 4 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ class Cfg(BaseSettings):
v0_union: Union[SubValue, int]
top: TopValue

args: list[str] = []
args: List[str] = []
args += ['--top', '{"v1": "json-1", "v2": "json-2", "sub": {"v5": "xx"}}']
args += ['--top.sub.v5', '5']
args += ['--v0', '0']
Expand Down Expand Up @@ -2067,7 +2067,7 @@ def check_answer(cfg, prefix, expected):
expected['child'] = None
assert cfg.model_dump() == expected

args: list[str] = []
args: List[str] = []
for prefix in ('', 'child.'):
args = [f'--{prefix}num_list', '[1,2]']
args += [f'--{prefix}num_list', '3,4']
Expand Down Expand Up @@ -2126,7 +2126,7 @@ class Cfg(BaseSettings):
check_dict: Optional[Dict[str, str]] = None
child: Optional[Child] = None

args: list[str] = []
args: List[str] = []
for prefix in ('', 'child.'):
args = [f'--{prefix}check_dict', '{"k1":"a","k2":"b"}']
args += [f'--{prefix}check_dict', '{"k3":"c"},{"k4":"d"}']
Expand All @@ -2142,7 +2142,7 @@ class Cfg(BaseSettings):
args += [f'--{prefix}check_dict', 'k29="x,y",k30="x,y"']
args += [f'--{prefix}check_dict', 'k31="x,y"', f'--{prefix}check_dict', 'k32="x,y"']
cfg = Cfg(_cli_parse_args=args)
expected: dict[str, Any] = {
expected: Dict[str, Any] = {
'check_dict': {
'k1': 'a',
'k2': 'b',
Expand Down

0 comments on commit 7ea4c97

Please sign in to comment.