Skip to content

Validate boolean defaults with boolean templates - #214

Closed
xingzhao-ji wants to merge 1 commit into
beetbox:mainfrom
xingzhao-ji:fix/boolean-default-template
Closed

xingzhao-ji wants to merge 1 commit into
beetbox:mainfrom
xingzhao-ji:fix/boolean-default-template

Conversation

@xingzhao-ji

@xingzhao-ji xingzhao-ji commented Oct 12, 2026 •

Copy link
Copy Markdown

Summary

as_template(False) and as_template(True) currently take the integer branch because bool subclasses int. A boolean default therefore accepts numeric values: validating {'enabled': 0.5} against {'enabled': False} returns integer 0, while validating with bool correctly rejects it.

Recognize boolean defaults before integers and reuse TypeTemplate(bool, default). Missing values retain the supplied boolean default, and existing boolean values retain their identity. Numeric values now raise ConfigTypeError, matching the explicit boolean template.

Add shorthand/default/validation tests and an unreleased changelog entry.

Validation

  • New tests before the fix: 10 failed, 10 controls passed.
  • Afterward: 319 passed, 1 skipped on Linux/Python 3.12.14 and 3.13.5. The skip is the release-script test because optional development dependencies are unavailable.
  • Available Ruff syntax/import checks and formatting checks passed. The project's complete Ruff configuration requires a newer version than the available tool.
  • Mypy produced the same seven existing environment/version diagnostics on pristine and patched source; no type-check pass is claimed.
  • git diff --check passed.

@xingzhao-ji
xingzhao-ji marked this pull request as ready for review October 14, 2026 17:55
@xingzhao-ji
xingzhao-ji marked this pull request as draft October 14, 2026 17:55
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