Skip to content

Single source of truth for user setting defaults and types - #753

Closed
0xSm0ky wants to merge 1 commit into
LuteOrg:developfrom
0xSm0ky:refactor/settings-single-source
Closed

0xSm0ky wants to merge 1 commit into
LuteOrg:developfrom
0xSm0ky:refactor/settings-single-source

Conversation

@0xSm0ky

@0xSm0ky 0xSm0ky commented Sep 8, 2026

Copy link
Copy Markdown

What

Refs #675.

The default user settings were defined in lute.db.management.add_default_user_settings, while the separate list of keys to coerce to booleans lived in lute.settings.current.refresh_global_settings. Keeping those two hand-maintained lists in sync was error prone, and (as noted in the issue) risked coercing an integer setting to a bool.

Change

  • Add lute/settings/setting_defaults.py as the single source: USER_SETTING_DEFINITIONS records each key's type (bool/int/str) and default value, with two helpers:
    • user_setting_defaults(default_user_backup_path) returns the key -> default map (with backup_dir filled in), consumed by add_default_user_settings.
    • bool_setting_keys() returns the keys to coerce to bool, consumed by refresh_global_settings.
  • add_default_user_settings and refresh_global_settings now both derive from that source, so defaults and bool-coercion can no longer drift, and integer keys are never coerced to bools.

Behavior note

Bool coercion is now derived from the declared types. The backup_enabled / backup_auto / backup_warn flags are bool-typed and are now coerced consistently in the global settings dict. These are only read elsewhere via UserSettingRepository.get_backup_settings (which does its own coercion) and are not read from LUTE_USER_SETTINGS, so there is no functional impact. All existing default values are unchanged.

Tests

  • tests/unit/settings/test_setting_defaults.py: covers user_setting_defaults and that bool_setting_keys matches the bool-typed keys (and excludes integer keys).
  • tests/unit/settings/test_current.py: asserts bool settings are coerced to real bools and integer settings are not.

black clean, pylint 10.00/10. Existing settings and db-management tests pass.

The default user settings lived in lute.db.management
(add_default_user_settings) while the list of keys to coerce to bools
lived separately in lute.settings.current (refresh_global_settings).
Keeping the two in sync by hand was error prone and risked coercing an
integer setting to a bool.

Add lute/settings/setting_defaults.py, which records each user setting
key's type and default value in one place, plus helpers:
- user_setting_defaults(path): key -> default map (backup_dir filled in),
  used by add_default_user_settings.
- bool_setting_keys(): keys whose stored string is coerced to bool, used
  by refresh_global_settings.

Bool coercion is now derived from the declared types, so integer keys
are never coerced.  The backup_enabled/backup_auto/backup_warn flags are
bool-typed and are now coerced consistently in the global settings dict;
they are only read elsewhere via UserSettingRepository.get_backup_settings
(which does its own coercion) and are not read from LUTE_USER_SETTINGS, so
this has no functional impact.

Refs #675.
@0xSm0ky 0xSm0ky closed this by deleting the head repository Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant