Skip to content

Fix constants argument silently discarding Constants subclasses#237

Merged
derek73 merged 2 commits into
masterfrom
fix/issue-226-constants-subclass
Jul 6, 2026
Merged

Fix constants argument silently discarding Constants subclasses#237
derek73 merged 2 commits into
masterfrom
fix/issue-226-constants-subclass

Conversation

@derek73

@derek73 derek73 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • The exact-type check in HumanName.__init__ (type(self.C) is not type(CONSTANTS)) silently replaced Constants subclass instances with fresh defaults, discarding the caller's configuration without any error (closes constants argument silently discards Constants subclasses #226)
  • Now validated explicitly: None → private per-instance Constants (unchanged); any Constants instance including subclasses → used as given; anything else → TypeError instead of a silent swap to defaults
  • The constants annotation now admits None (always accepted and documented); fixed stale customize.rst prose ("pass something falsey" → only None; constantconstants keyword typo)

Behavior notes

  • Previously, garbage values (e.g. a string, or falsey values like ""/0) were silently replaced with fresh defaults; they now raise TypeError — called out in the release log

Test plan

  • Two tests written first (TDD, both verified failing): a customized Constants subclass instance is kept (assertIs) and honored by parsing; a non-Constants value raises TypeError
  • Full suite 1360 passed / 22 xfailed (incl. doctests), mypy clean, Sphinx doctest build clean (docs prose changed)

🤖 Generated with Claude Code

derek73 and others added 2 commits July 5, 2026 15:36
__init__ validated the constants argument with an exact-type check
(type(self.C) is not type(CONSTANTS)), so an instance of a Constants
subclass failed the check and was silently replaced with fresh
defaults, discarding the caller's configuration without any error.

Validate explicitly instead: None means a private per-instance
Constants (unchanged), any Constants instance — including subclasses —
is used as given, and anything else raises TypeError rather than being
silently swapped for defaults. The signature annotation now admits
None, which was always accepted and documented.

Also fix stale prose in customize.rst: "pass something falsey" no
longer describes the behavior (only None gets per-instance config now),
and the keyword argument is `constants`, not `constant`.

Closes #226

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The likeliest wrong constants argument is the Constants class itself
(forgotten parentheses), which the TypeError reported as an unhelpful
"got type"; special-case classes with a did-you-mean hint, test-driven
with pytest.raises match patterns (also tightened the existing bare
TypeError check, which any TypeError in __init__ would have satisfied).

Sweep prose left stale by this fix: the config module "Potential
Gotcha" docstring had the same only-None phrasing corrected in
customize.rst; the AGENTS.md mypy note attributed most test-suite
errors to the constants=None pattern, an error class the Constants|None
annotation eliminated; and the :param constants: docstring now
documents the TypeError and drops its malformed type spec.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.26%. Comparing base (d7ad5b6) to head (84b81cc).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #237      +/-   ##
==========================================
+ Coverage   97.25%   97.26%   +0.01%     
==========================================
  Files          13       13              
  Lines         802      805       +3     
==========================================
+ Hits          780      783       +3     
  Misses         22       22              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@derek73 derek73 self-assigned this Jul 6, 2026
@derek73 derek73 added the bug label Jul 6, 2026
@derek73 derek73 added this to the v1.3.0 milestone Jul 6, 2026
@derek73 derek73 merged commit 192d35e into master Jul 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

constants argument silently discards Constants subclasses

2 participants