Skip to content

Add Constants.copy(); deprecate constants=None#282

Merged
derek73 merged 2 commits into
masterfrom
feature/260-constants-copy-none-deprecation
Jul 12, 2026
Merged

Add Constants.copy(); deprecate constants=None#282
derek73 merged 2 commits into
masterfrom
feature/260-constants-copy-none-deprecation

Conversation

@derek73

@derek73 derek73 commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • constants=None means "build a fresh private Constants()" -- a sentinel meaning the opposite of what None conventionally means, since the default is the shared CONSTANTS. Easy trap: customize CONSTANTS, later pass None elsewhere for "my own config," and those customizations silently vanish with no error.
  • Add Constants.copy(): a detached deep copy that preserves the source's current customizations (unlike Constants(), which always starts from library defaults) -- the missing explicit spelling for "private snapshot of the current shared config," e.g. CONSTANTS.copy().
  • Passing constants=None (to the constructor or hn.C = None) still works but now emits DeprecationWarning naming both replacements (Constants() / CONSTANTS.copy()). Removal is Remove constants=None; explicit None raises with migration hint #261 (2.0).
  • Migrated every internal constants=None / HumanName(name, None) usage across tests and docs to the explicit spellings, so the suite's own output stays warning-free.
  • Docs: reworked the "Module-level Shared Configuration Instance" section and the nameparser.config module docstring with the three-spelling vocabulary and a .. deprecated:: note.

Test plan

  • New ConstantsCopyTests and ConstantsNoneDeprecationTests in tests/test_constants.py (written first, watched fail, then implemented -- TDD)
  • Full suite: pytest tests/ nameparser/ -- 1500 passed, 4 skipped, 22 xfailed, no stray warnings
  • mypy nameparser/ tests/ -- clean

Fixes #260

constants=None means "build a fresh private Constants()" -- a sentinel
that means the opposite of what None conventionally means, since the
default is the *shared* CONSTANTS. It's an easy trap: customize
CONSTANTS, later pass None elsewhere for "my own config", and those
customizations silently vanish with no error.

Constants.copy() gives an explicit spelling for the missing answer --
a private snapshot of the current shared config, as opposed to
Constants()'s fresh library defaults. Passing constants=None still
works but now emits a DeprecationWarning naming both replacements;
removal is #261 (2.0).

Migrates every internal constants=None / HumanName(name, None) usage
in tests and docs to the explicit spellings so the suite's own output
stays warning-free.

Fixes #260.
@derek73 derek73 self-assigned this Jul 12, 2026
@codecov-commenter

codecov-commenter commented Jul 12, 2026

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.70%. Comparing base (59fdabb) to head (a0933bc).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #282      +/-   ##
==========================================
+ Coverage   97.69%   97.70%   +0.01%     
==========================================
  Files          13       13              
  Lines         913      917       +4     
==========================================
+ Hits          892      896       +4     
  Misses         21       21              

☔ 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 added the breaking-change Backwards-incompatible API change label Jul 12, 2026
@derek73 derek73 added this to the v1.4 milestone Jul 12, 2026
@derek73 derek73 added enhancement and removed breaking-change Backwards-incompatible API change labels Jul 12, 2026
copy() is deepcopy-based (restored via __getstate__/__setstate__, not
by re-invoking type(self)(...)), so a naive reimplementation could
silently downgrade a subclass instance to plain Constants with no
existing test catching it.

Found in review of #282.
@derek73 derek73 merged commit 18c9b6a into master Jul 12, 2026
8 checks passed
@derek73 derek73 deleted the feature/260-constants-copy-none-deprecation branch July 12, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Constants.copy(); deprecate constants=None

2 participants