33import logging
44import os
55from pathlib import Path
6- from typing import TYPE_CHECKING , Any
6+ from typing import TYPE_CHECKING , Any , Optional
77
88import boto3
99from botocore .client import Config
1212from pydantic ._internal ._utils import lenient_issubclass
1313from pydantic .fields import FieldInfo
1414from pydantic_settings import BaseSettings
15- from pydantic_settings .sources import (
16- EnvSettingsSource ,
17- )
15+ from pydantic_settings .sources import EnvSettingsSource
1816
1917if TYPE_CHECKING :
2018 from mypy_boto3_ssm .client import SSMClient
@@ -31,8 +29,8 @@ class AwsSsmSettingsSource(EnvSettingsSource):
3129 def __init__ (
3230 self ,
3331 settings_cls : type [BaseSettings ],
34- case_sensitive : bool = None ,
35- ssm_prefix : str = None ,
32+ case_sensitive : Optional [ bool ] = None ,
33+ ssm_prefix : Optional [ str ] = None ,
3634 ):
3735 # Ideally would retrieve ssm_prefix from self.config
3836 # but need the superclass to be initialized for that
@@ -62,9 +60,7 @@ def client_config(self) -> Config:
6260 def _load_env_vars (
6361 self ,
6462 ):
65- """
66- Access env_prefix instead of ssm_prefix
67- """
63+ # NOTE: env_prefix represents the ssm_prefix
6864 if not Path (self .env_prefix ).is_absolute ():
6965 raise ValueError ("SSM prefix must be absolute path" )
7066
@@ -83,9 +79,11 @@ def _load_env_vars(
8379 Path (parameter ["Name" ]).relative_to (self .env_prefix ).as_posix ()
8480 )
8581 output [
86- self .env_prefix + key
87- if self .case_sensitive
88- else self .env_prefix .lower () + key .lower ()
82+ (
83+ self .env_prefix + key
84+ if self .case_sensitive
85+ else self .env_prefix .lower () + key .lower ()
86+ )
8987 ] = parameter ["Value" ]
9088
9189 except ClientError :
@@ -143,7 +141,7 @@ def __call__(self) -> dict[str, Any]:
143141 )
144142 except ValueError as e :
145143 raise SettingsError (
146- f'error parsing value for field "{ field_name } " from source "{ self .__class__ .__name__ } "' # noqa
144+ f'error parsing value for field "{ field_name } " from source "{ self .__class__ .__name__ } "' # noqa
147145 ) from e
148146
149147 if field_value is not None :
0 commit comments