Repository navigation
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Add coverage confirming normalized keys with empty-string values retain precedence.
Pull request overview
Adds a narrowly scoped fallback for uppercase environment names containing digit-to-letter boundaries while preserving existing lookup precedence.
Changes:
- Implements the fallback candidate logic.
- Documents updated
ENVlookup behavior. - Adds regression coverage for numeric names, precedence, aliases, prefixes, and strategies.
File summaries
| File | Description |
|---|---|
tests/unit/environ/test_numeric_names.py |
Regression tests for numeric environment names |
dataclass_wizard/utils/_string_conv.py |
Implements the fallback candidate logic |
dataclass_wizard/enums.py |
Documents the new lookup behavior |
Review details
Suppressed comments (1)
tests/unit/environ/test_numeric_names.py:26
- The PR description explicitly guarantees that a normalized key still wins when its value is an empty string, but this precedence parameterization only exercises non-empty values. Add an empty-string case so a future truthiness check cannot regress this behavior without being caught.
@pytest.mark.parametrize('values, expected', [
({'CC_2TEST': 'original'}, 'original'),
({'CC_2TEST': 'original', 'cc_2_test': 'snake'}, 'snake'),
({'CC_2TEST': 'original', 'cc_2_test': 'snake', 'CC_2_TEST': 'upper'},
'upper'),
])
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Added three precedence cases covering empty normalized values while the original spelling remains non-empty. Both normalized candidates retain priority, including when both are empty. All 80 environment tests pass on Python 3.12 and 3.14; this update changes tests only. The full-suite and platform-validation limitations recorded in the PR description remain unchanged; this update does not claim a full-suite or CI pass. |
Related #250.
With the default ENV lookup strategy, a field named
CC_2TESTonly checksCC_2_TESTandcc_2_test. A same-named environment variable or dotenv entry is therefore ignored, and the field keeps its default or raises MissingVars.This change adds the original spelling as a final fallback only for ASCII uppercase environment identifiers whose normalization consists exclusively of inserting underscores between digits and uppercase letters. For example, the lookup order becomes
CC_2_TEST,cc_2_test, thenCC_2TEST. Existing normalized keys still win when multiple spellings are present, including when their value is an empty string.The shared snake-case conversion is unchanged. FIELD_FIRST, STRICT, explicit alias precedence, and prefix handling retain their existing behavior. Mixed-case names, punctuation, and names whose normalization also collapses repeated underscores do not gain this fallback. The ENV strategy docstring describes the new lookup behavior. This is a proposed limited compatibility fix, not a previously confirmed maintainer policy.
Validation:
2021-12-18versus2021-12-17). These are not full-suite passes; Python 3.14 coverage is 89% under the existing coverage configuration.twine check.Tests ran on Windows using a task-local synthetic process environment. The full supported Python/PyPy and Linux CI matrix has not been run locally.
The README's EnvWizard feature list now documents the numeric-name fallback and the priority of existing normalized keys, including empty values.