Skip to content

Make an empty RichText falsy - #205

Merged
cvas22 merged 1 commit into
mainfrom
fix/138-empty-richtext-falsy
Nov 25, 2026
Merged

cvas22 merged 1 commit into
mainfrom
fix/138-empty-richtext-falsy

Conversation

@cvas22

@cvas22 cvas22 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

RichText didn't define __bool__, so {%r if e.habitat %} was always true for a RichText, even RichText("", color="blue"). That's the doubled separator in #138.

RichText and RichTextParagraph are now false when none of their w:t elements has any text, which matches how an empty string behaves in the same template. Whitespace still counts as text. RichTextParagraph(RichText("")) keeps producing an empty paragraph, since its constructor used to rely on the RichText being truthy.

This is a small behaviour change: a template that relied on an empty RichText being true will now skip it. I couldn't think of a case where that was intended, but it should get a line in the changelog for the next release.

Tests cover bool() for the empty and non-empty cases and the {%r if %} template from the report. Both fail on main.

Fixes #138

RichText("", color=...) is an object, so it was always true and
{%r if rt %} couldn't tell it was empty. RichText and RichTextParagraph
are now false when they hold no text. RichTextParagraph(RichText(""))
still makes an empty paragraph, as before.

Fixes #138
@github-actions github-actions Bot added code Changes to the docform package tests Changes to tests labels Nov 25, 2026
@cvas22
cvas22 merged commit 57c215c into main Nov 25, 2026
11 checks passed
@cvas22
cvas22 deleted the fix/138-empty-richtext-falsy branch November 25, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code Changes to the docform package tests Changes to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

how to make template to detect empty richtext fields

1 participant