Add Constants.copy(); deprecate constants=None#282
Merged
Conversation
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.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
constants=Nonemeans "build a fresh privateConstants()" -- a sentinel meaning the opposite of whatNoneconventionally means, since the default is the sharedCONSTANTS. Easy trap: customizeCONSTANTS, later passNoneelsewhere for "my own config," and those customizations silently vanish with no error.Constants.copy(): a detached deep copy that preserves the source's current customizations (unlikeConstants(), which always starts from library defaults) -- the missing explicit spelling for "private snapshot of the current shared config," e.g.CONSTANTS.copy().constants=None(to the constructor orhn.C = None) still works but now emitsDeprecationWarningnaming both replacements (Constants()/CONSTANTS.copy()). Removal is Remove constants=None; explicit None raises with migration hint #261 (2.0).constants=None/HumanName(name, None)usage across tests and docs to the explicit spellings, so the suite's own output stays warning-free.nameparser.configmodule docstring with the three-spelling vocabulary and a.. deprecated::note.Test plan
ConstantsCopyTestsandConstantsNoneDeprecationTestsintests/test_constants.py(written first, watched fail, then implemented -- TDD)pytest tests/ nameparser/-- 1500 passed, 4 skipped, 22 xfailed, no stray warningsmypy nameparser/ tests/-- cleanFixes #260