Skip to content

Fix str() scrubbing literal "None" from names when empty_attribute_default is None#277

Merged
derek73 merged 1 commit into
masterfrom
fix/254-str-none-scrub
Jul 11, 2026
Merged

Fix str() scrubbing literal "None" from names when empty_attribute_default is None#277
derek73 merged 1 commit into
masterfrom
fix/254-str-none-scrub

Conversation

@derek73

@derek73 derek73 commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary

With empty_attribute_default = None, __str__ formatted the template with raw attribute values and then deleted every occurrence of "None" from the result — a scrub (dating to PR #45, 2016) that couldn't distinguish the interpolated None from real name text containing the same substring:

c = Constants()
c.empty_attribute_default = None
str(HumanName("Nonez Smith", constants=c))   # 'z Smith'

The fix substitutes '' for falsy attributes before str.format() runs and deletes the scrub outright, mirroring how initials() was fixed for the same bug family in 1.3.0. This also removes the latent corruption for any custom empty_attribute_default string (e.g. "N/A") appearing in real name text.

Closes #254

Testing

  • Two regression tests in tests/test_output_format.py: a name containing "None" as a substring and a name piece that is exactly None (both watched failing with 'z Smith' before the fix)
  • Full suite: 1472 passed, 22 xfailed; mypy and ruff clean
  • Release log entry added under 1.3.1 - Unreleased

🤖 Generated with Claude Code

…fault is None

__str__ formatted the template with raw attribute values and then deleted
every occurrence of str(empty_attribute_default) from the result — a scrub
that couldn't distinguish the interpolated None from real name text
containing the same substring, so HumanName("Nonez Smith") rendered as
"z Smith" in None-mode. Substitute '' for falsy attributes before
str.format() instead, mirroring the initials() fix from 1.3.0, and delete
the scrub.

Closes #254

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@derek73 derek73 added this to the 1.3.1 milestone Jul 11, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.69%. Comparing base (770ed0a) to head (c8b245a).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #277   +/-   ##
=======================================
  Coverage   97.69%   97.69%           
=======================================
  Files          13       13           
  Lines         912      912           
=======================================
  Hits          891      891           
  Misses         21       21           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@derek73 derek73 self-assigned this Jul 11, 2026
@derek73 derek73 added the bug label Jul 11, 2026
@derek73 derek73 merged commit f09c2c6 into master Jul 11, 2026
8 checks passed
@derek73 derek73 deleted the fix/254-str-none-scrub branch July 11, 2026 08:44
@derek73 derek73 mentioned this pull request Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants