You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A default HumanName shares the module-level CONSTANTS singleton as its .C. pickle and copy.deepcopy cannot preserve object identity, so after a
round-trip .C is a detached copy rather than the singleton. This flips has_own_config from False to True and bloats every serialized default name
with a full Constants copy (~1000+ entries).
Surfaced during the round-trip work in #168 (which fixes the value-level
round-trip bugs but deliberately leaves this identity/semantic issue out of
scope).
(self.C is never legitimately None — the constructor replaces None with a
fresh Constants — so None is a safe sentinel. Confirm before relying on it.)
Notes / things to decide
This changes HumanName serialization semantics, so it warrants its own PR and
a changelog note.
Needs tests: default name round-trips with .C is CONSTANTS and has_own_config == False; an instance-config name still round-trips its own
config (covered today by the tests added in Fix pickle/copy round-trip bugs in Constants and config managers #168); both pickle and copy.deepcopy.
Decide whether copy.copy (shallow) behavior should match.
Summary
A default
HumanNameshares the module-levelCONSTANTSsingleton as its.C.pickleandcopy.deepcopycannot preserve object identity, so after around-trip
.Cis a detached copy rather than the singleton. This flipshas_own_configfromFalsetoTrueand bloats every serialized default namewith a full
Constantscopy (~1000+ entries).Surfaced during the round-trip work in #168 (which fixes the value-level
round-trip bugs but deliberately leaves this identity/semantic issue out of
scope).
Reproduction
Impact
has_own_configreportsTruefor a name that was using the shared config —the property effectively lies after a round-trip.
CONSTANTS.Constantscopy insteadof a reference. Real memory/size cost when serializing names in bulk.
This is pre-existing (the old serialization also copied
.Cby value); #168 didnot introduce it.
Proposed fix
Add
HumanName.__getstate__/__setstate__(or__reduce__) that special-caseself.C is CONSTANTSand restore the reference instead of a copy. Sketch:(
self.Cis never legitimatelyNone— the constructor replacesNonewith afresh
Constants— soNoneis a safe sentinel. Confirm before relying on it.)Notes / things to decide
HumanNameserialization semantics, so it warrants its own PR anda changelog note.
.C is CONSTANTSandhas_own_config == False; an instance-config name still round-trips its ownconfig (covered today by the tests added in Fix pickle/copy round-trip bugs in Constants and config managers #168); both
pickleandcopy.deepcopy.copy.copy(shallow) behavior should match.