Skip to content

Commit d9fff32

Browse files
committed
Improve settings: resolve custom setting annotations and enhance secret display
Resolve type annotations for custom settings using typing.get_type_hints, and show item counts for secret collection values (dict, list, tuple) instead of a plain mask.
1 parent b375353 commit d9fff32

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

plain/plain/runtime/user_settings.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ def _load_explicit_settings(self, settings_module: types.ModuleType) -> None:
165165

166166
elif setting.startswith(_CUSTOM_SETTINGS_PREFIX):
167167
# Accept custom settings prefixed with '{_CUSTOM_SETTINGS_PREFIX}'
168+
annotation = _get_annotation(settings_module, setting)
168169
setting_def = SettingDefinition(
169170
name=setting,
170171
default_value=None,
171-
annotation=None,
172+
annotation=annotation,
172173
required=False,
173174
)
174175
try:
@@ -257,6 +258,15 @@ def get_env_settings(self) -> list[tuple[str, SettingDefinition]]:
257258
return self.get_settings(source="env")
258259

259260

261+
def _get_annotation(module: types.ModuleType, setting: str) -> type | None:
262+
"""Get the resolved type annotation for a setting, handling string annotations."""
263+
try:
264+
hints = typing.get_type_hints(module, include_extras=True)
265+
return hints.get(setting, None)
266+
except Exception:
267+
return None
268+
269+
260270
def _parse_env_value(
261271
value: str, annotation: type | None, setting_name: str
262272
) -> typing.Any:
@@ -314,7 +324,13 @@ def _check_if_secret(annotation: type | None) -> bool:
314324

315325
def display_value(self) -> str:
316326
"""Return value for display, masked if secret."""
317-
if self.is_secret:
327+
if self.is_secret and self.value:
328+
if isinstance(self.value, dict):
329+
return f"{{******** ({len(self.value)} items)}}"
330+
if isinstance(self.value, list):
331+
return f"[******** ({len(self.value)} items)]"
332+
if isinstance(self.value, tuple):
333+
return f"(******** ({len(self.value)} items))"
318334
return "********"
319335
return repr(self.value)
320336

0 commit comments

Comments
 (0)