With empty_attribute_default = None, __str__ interpolates None into the formatted string and then scrubs it with .replace(str(self.C.empty_attribute_default), '') (a hack dating to PR #45, 2016). The scrub can't distinguish the interpolated None from name text containing the same substring:
c = Constants()
c.empty_attribute_default = None
str(HumanName("Nonez Smith", constants=c)) # 'z Smith'
The parse is correct (first='Nonez'); the formatted output silently corrupts the name. Present since 2016; None-mode only. initials() had the same family of bug, fixed in 1.3.0.
Fix: substitute '' for falsy fields before str.format() (e.g. format a {k: v or '' for ...} view of as_dict()) instead of scrubbing 'None' after — which also deletes the replace hack outright. Related: #255 removes the option entirely in 2.0; this fix protects users during the deprecation window.
With
empty_attribute_default = None,__str__interpolatesNoneinto the formatted string and then scrubs it with.replace(str(self.C.empty_attribute_default), '')(a hack dating to PR #45, 2016). The scrub can't distinguish the interpolatedNonefrom name text containing the same substring:The parse is correct (
first='Nonez'); the formatted output silently corrupts the name. Present since 2016; None-mode only.initials()had the same family of bug, fixed in 1.3.0.Fix: substitute
''for falsy fields beforestr.format()(e.g. format a{k: v or '' for ...}view ofas_dict()) instead of scrubbing'None'after — which also deletes the replace hack outright. Related: #255 removes the option entirely in 2.0; this fix protects users during the deprecation window.