Skip to content

feat: add opt-in strict Literal loading - #261

Open
edsonsims wants to merge 1 commit into
rnag:mainfrom
edsonsims:feat/strict-literal-loading
Open

edsonsims wants to merge 1 commit into
rnag:mainfrom
edsonsims:feat/strict-literal-loading

Conversation

@edsonsims

Copy link
Copy Markdown

Adds the opt-in strict_mode_for_literals requested in #170. With the option enabled, a loaded value must match both the value and exact type of a Literal argument: False no longer matches Literal[0], and an integer does not match an equal-valued IntEnum member. Mixed alternatives such as Literal[0, False] retain both choices. The default value-only matching remains unchanged.

The option works through JSONWizard.Meta/LoadMeta and EnvWizard.Meta/EnvMeta. It follows recursive Meta settings, while keeping sibling classes and their cached Literal/optional TypedDict loaders independent. Env loading uses the same value check; it does not add coercion of raw environment strings ('0' still does not match Literal[0]). Other field coercion, dumping and the legacy dataclass_wizard.v0 implementation are unchanged. Includes typed declarations, usage docs, README and changelog entries.

Validation:

  • The 42 new cases produce 26 failures and 16 passing controls on the original source, then all pass on Python 3.10.16 and 3.13.1. They cover bool/int/float/enum distinctions, mixed alternatives, containers, optional/union values, inherited/recursive metadata, sibling declaration order and synthetic Env inputs.
  • Canonical make test on Python 3.13.1: 926 passed, 2 skipped, 6 xfailed, 4 xpassed. All 896 existing case outcomes remain unchanged; 42 cases are added.
  • Full-package mypy passes (47 source files); README rstcheck and AST checks pass. Sphinx HTML builds with the same 89 warnings as the original source.
  • make lint remains nonzero on both trees: existing flake8 diagnostics decrease from 1,782 to 1,776. The Pylint command was also run separately because flake8 stops the target; it remains nonzero on both (4,038 to 4,036 diagnostics). Its existing statement-count warning changes from 198 to 200 for the metadata isolation/configuration statements. The new test file has no Ruff, flake8 or Pylint diagnostics.

The full tox matrix, PyPy, and Python 3.9/3.11/3.12/3.14 were not run locally.

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