Skip to content

Commit f0fee99

Browse files
committed
Fix format error
1 parent e5e9c5e commit f0fee99

File tree

2 files changed

+14
-32
lines changed

2 files changed

+14
-32
lines changed

pydantic_settings/sources/providers/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,7 @@ def _is_nested_alias_path_only_workaround(
583583
return True
584584
return False
585585

586-
def _get_merge_parsed_list_types(
587-
self, parsed_list: list[str], field_name: str
588-
) -> tuple[type | None, type | None]:
586+
def _get_merge_parsed_list_types(self, parsed_list: list[str], field_name: str) -> tuple[type | None, type | None]:
589587
merge_type = self._cli_dict_args.get(field_name, list)
590588
if (
591589
merge_type is list

tests/test_source_cli.py

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ class CfgWithSubCommand(BaseSettings):
20712071
(List[Dict[str, int]], 'List[Dict[str,int]]'), # noqa: UP006
20722072
(Tuple[str, int, float], 'Tuple[str,int,float]'), # noqa: UP006
20732073
(Tuple[str, ...], 'Tuple[str,...]'), # noqa: UP006
2074-
(Union[int, List[str], Tuple[str, int]], '{int,List[str],Tuple[str,int]}'), # noqa: UP006
2074+
(int | List[str] | Tuple[str, int], '{int,List[str],Tuple[str,int]}'), # noqa: UP006
20752075
(foobar, 'foobar'),
20762076
(LoggedVar, 'LoggedVar'),
20772077
(LoggedVar(), 'LoggedVar'),
@@ -2082,36 +2082,14 @@ class CfgWithSubCommand(BaseSettings):
20822082
(typing_extensions.Literal['a', 'b', 'c'], '{a,b,c}'),
20832083
(SimpleSettings, 'JSON'),
20842084
(SimpleSettings | SettingWithIgnoreEmpty, 'JSON'),
2085-
(Union[SimpleSettings, str, SettingWithIgnoreEmpty], '{JSON,str}'),
2086-
(Union[str, SimpleSettings, SettingWithIgnoreEmpty], '{str,JSON}'),
2085+
(Union[SimpleSettings, str, SettingWithIgnoreEmpty], '{JSON,str}'), # noqa: UP007
2086+
(Union[str, SimpleSettings, SettingWithIgnoreEmpty], '{str,JSON}'), # noqa: UP007
20872087
(Annotated[SimpleSettings, 'annotation'], 'JSON'),
20882088
(DirectoryPath, 'Path'),
20892089
(FruitsEnum, '{pear,kiwi,lime}'),
20902090
(time.time_ns, 'time_ns'),
20912091
(foobar, 'foobar'),
20922092
(CliDummyParser.add_argument, 'CliDummyParser.add_argument'),
2093-
],
2094-
)
2095-
@pytest.mark.parametrize('hide_none_type', [True, False])
2096-
def test_cli_metavar_format(hide_none_type, value, expected):
2097-
cli_settings = CliSettingsSource(SimpleSettings, cli_hide_none_type=hide_none_type)
2098-
if hide_none_type:
2099-
if value == [1, 2, 3] or isinstance(value, LoggedVar) or isinstance(value, Representation):
2100-
pytest.skip()
2101-
if value in ('foobar', 'SomeForwardRefString'):
2102-
expected = f"ForwardRef('{value}')" # forward ref implicit cast
2103-
if typing_extensions.get_origin(value) is Union:
2104-
args = typing_extensions.get_args(value)
2105-
value = Union[args + (None,) if args else (value, None)]
2106-
else:
2107-
value = Union[(value, None)]
2108-
assert cli_settings._metavar_format(value) == expected
2109-
2110-
2111-
@pytest.mark.skipif(sys.version_info < (3, 10), reason='requires python 3.10 or higher')
2112-
@pytest.mark.parametrize(
2113-
'value_gen,expected',
2114-
[
21152093
(lambda: str | int, '{str,int}'),
21162094
(lambda: list[int], 'list[int]'),
21172095
(lambda: List[int], 'List[int]'), # noqa: UP006
@@ -2123,15 +2101,21 @@ def test_cli_metavar_format(hide_none_type, value, expected):
21232101
],
21242102
)
21252103
@pytest.mark.parametrize('hide_none_type', [True, False])
2126-
def test_cli_metavar_format_310(hide_none_type, value_gen, expected):
2127-
value = value_gen()
2104+
def test_cli_metavar_format(hide_none_type, value, expected):
2105+
if callable(value) and value.__name__ == '<lambda>':
2106+
value = value()
2107+
21282108
cli_settings = CliSettingsSource(SimpleSettings, cli_hide_none_type=hide_none_type)
21292109
if hide_none_type:
2110+
if value == [1, 2, 3] or isinstance(value, LoggedVar) or isinstance(value, Representation):
2111+
pytest.skip()
2112+
if value in ('foobar', 'SomeForwardRefString'):
2113+
expected = f"ForwardRef('{value}')" # forward ref implicit cast
21302114
if typing_extensions.get_origin(value) is Union:
21312115
args = typing_extensions.get_args(value)
2132-
value = Union[args + (None,) if args else (value, None)]
2116+
value = Union[args + (None,) if args else (value, None)] # noqa: UP007
21332117
else:
2134-
value = Union[(value, None)]
2118+
value = Union[(value, None)] # noqa: UP007
21352119
assert cli_settings._metavar_format(value) == expected
21362120

21372121

0 commit comments

Comments
 (0)