Skip to content

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

Closed

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

  1. added this to the v1.4 milestone on Jul 6, 2026
  2. self-assigned this
    on Jul 6, 2026
  3. derek73 commented on Jul 8, 2026

    @derek73
    OwnerAuthor

    #255 removes theempty_attribute_default property entirely so not if sure this is worth doing.

  4. modified the milestones: v1.4, 1.3.1 on Jul 11, 2026
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