-
-
Notifications
You must be signed in to change notification settings - Fork 109
Closed
Labels
Description
When using Python 3.9 or earlier with Pydantic 2.10, metavar in CliSettingsSource is not generated correctly.
This issue is caused by changes introduced in Pydantic 2.10 related to WithArgsTypes. Since CliSettingsSource relies on WithArgsTypes for metavar generation, its behavior has changed unexpectedly.
pydantic-settings/pydantic_settings/sources.py
Lines 2001 to 2005 in 4b6fd3d
| elif isinstance(obj, WithArgsTypes): | |
| return self._metavar_format_choices( | |
| list(map(self._metavar_format_recurse, self._get_modified_args(obj))), | |
| obj_qualname=obj.__qualname__ if hasattr(obj, '__qualname__') else str(obj), | |
| ) |
This issue does not occur in Python 3.10 or later.
Reproduction Code
import sys
from typing import List
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(cli_parse_args=True)
val: List[str]
sys.argv = ['main.py', '-h']
Settings()When running this code, the output looks like this. The type of val is displayed as typing.List[str][str], but it should be List[str].
usage: main.py [-h] [--val typing.List[str][str]]
optional arguments:
-h, --help show this help message and exit
--val typing.List[str][str]
(required)