Skip to content

Commit

Permalink
Use self.__class__.__name__ in sources __repr__()
Browse files Browse the repository at this point in the history
  • Loading branch information
dlax committed Nov 6, 2024
1 parent e66959e commit 02cd346
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ def __call__(self) -> dict[str, Any]:
return self.defaults

def __repr__(self) -> str:
return f'DefaultSettingsSource(nested_model_default_partial_update={self.nested_model_default_partial_update})'
return (
f'{self.__class__.__name__}(nested_model_default_partial_update={self.nested_model_default_partial_update})'
)


class InitSettingsSource(PydanticBaseSettingsSource):
Expand Down Expand Up @@ -383,7 +385,7 @@ def __call__(self) -> dict[str, Any]:
)

def __repr__(self) -> str:
return f'InitSettingsSource(init_kwargs={self.init_kwargs!r})'
return f'{self.__class__.__name__}(init_kwargs={self.init_kwargs!r})'


class PydanticBaseEnvSettingsSource(PydanticBaseSettingsSource):
Expand Down Expand Up @@ -673,7 +675,7 @@ def get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str,
return None, field_key, value_is_complex

def __repr__(self) -> str:
return f'SecretsSettingsSource(secrets_dir={self.secrets_dir!r})'
return f'{self.__class__.__name__}(secrets_dir={self.secrets_dir!r})'


class EnvSettingsSource(PydanticBaseEnvSettingsSource):
Expand Down Expand Up @@ -898,7 +900,7 @@ def explode_env_vars(self, field_name: str, field: FieldInfo, env_vars: Mapping[

def __repr__(self) -> str:
return (
f'EnvSettingsSource(env_nested_delimiter={self.env_nested_delimiter!r}, '
f'{self.__class__.__name__}(env_nested_delimiter={self.env_nested_delimiter!r}, '
f'env_prefix_len={self.env_prefix_len!r})'
)

Expand Down Expand Up @@ -1014,7 +1016,7 @@ def __call__(self) -> dict[str, Any]:

def __repr__(self) -> str:
return (
f'DotEnvSettingsSource(env_file={self.env_file!r}, env_file_encoding={self.env_file_encoding!r}, '
f'{self.__class__.__name__}(env_file={self.env_file!r}, env_file_encoding={self.env_file_encoding!r}, '
f'env_nested_delimiter={self.env_nested_delimiter!r}, env_prefix_len={self.env_prefix_len!r})'
)

Expand Down Expand Up @@ -1952,7 +1954,7 @@ def _read_file(self, file_path: Path) -> dict[str, Any]:
return json.load(json_file)

def __repr__(self) -> str:
return f'JsonConfigSettingsSource(json_file={self.json_file_path})'
return f'{self.__class__.__name__}(json_file={self.json_file_path})'


class TomlConfigSettingsSource(InitSettingsSource, ConfigFileSourceMixin):
Expand All @@ -1977,7 +1979,7 @@ def _read_file(self, file_path: Path) -> dict[str, Any]:
return tomllib.load(toml_file)

def __repr__(self) -> str:
return f'TomlConfigSettingsSource(toml_file={self.toml_file_path})'
return f'{self.__class__.__name__}(toml_file={self.toml_file_path})'


class PyprojectTomlConfigSettingsSource(TomlConfigSettingsSource):
Expand Down Expand Up @@ -2052,7 +2054,7 @@ def _read_file(self, file_path: Path) -> dict[str, Any]:
return yaml.safe_load(yaml_file) or {}

def __repr__(self) -> str:
return f'YamlConfigSettingsSource(yaml_file={self.yaml_file_path})'
return f'{self.__class__.__name__}(yaml_file={self.yaml_file_path})'


class AzureKeyVaultMapping(Mapping[str, Optional[str]]):
Expand Down Expand Up @@ -2116,7 +2118,7 @@ def _load_env_vars(self) -> Mapping[str, Optional[str]]:
return AzureKeyVaultMapping(secret_client)

def __repr__(self) -> str:
return f'AzureKeyVaultSettingsSource(url={self._url!r}, ' f'env_nested_delimiter={self.env_nested_delimiter!r})'
return f'{self.__class__.__name__}(url={self._url!r}, ' f'env_nested_delimiter={self.env_nested_delimiter!r})'


def _get_env_var_key(key: str, case_sensitive: bool = False) -> str:
Expand Down

0 comments on commit 02cd346

Please sign in to comment.