Skip to content

str() strips literal "None" from real names when empty_attribute_default is None #254

Description

@derek73

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions