Skip to content

Removed Text.from_ansi() monkeypatch (3.x)#1631

Merged
kmvanbrunt merged 1 commit into3.xfrom
remove_rich_patch_3.x
Apr 13, 2026
Merged

Removed Text.from_ansi() monkeypatch (3.x)#1631
kmvanbrunt merged 1 commit into3.xfrom
remove_rich_patch_3.x

Conversation

@kmvanbrunt
Copy link
Copy Markdown
Member

No description provided.

@kmvanbrunt kmvanbrunt requested a review from tleonhardt as a code owner April 13, 2026 15:18
@github-actions
Copy link
Copy Markdown
Contributor

🤖 Hi @kmvanbrunt, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (3.x@8a48700). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             3.x    #1631   +/-   ##
======================================
  Coverage       ?   99.21%           
======================================
  Files          ?       21           
  Lines          ?     4862           
  Branches       ?        0           
======================================
  Hits           ?     4824           
  Misses         ?       38           
  Partials       ?        0           
Flag Coverage Δ
unittests 99.21% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

## 📋 Review Summary

This Pull Request successfully removes the Text.from_ansi() monkey patch from cmd2/rich_utils.py, following the fix in the upstream rich library. By increasing the minimum rich version to 15.0.0, the workaround is no longer necessary, leading to a cleaner codebase.

🔍 General Feedback

  • Regression Testing: While the monkey patch itself is obsolete, it is recommended to retain the functional part of the Text.from_ansi test to ensure the library's behavior remains consistent with cmd2's requirements across future updates.
  • Changelog: Consider adding an entry to CHANGELOG.md to document the rich version bump and the removal of the monkey patch.

assert ru.APP_THEME.styles[rich_style_key] == theme[rich_style_key]


def test_from_ansi_wrapper() -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 While the monkey patch is being removed, it is beneficial to keep a simplified version of this test as a regression check. This ensures that the required version of the rich library (>= 15.0.0) continues to provide the behavior cmd2 expects regarding trailing newlines.

Suggested change
def test_from_ansi_wrapper() -> None:
def test_text_from_ansi() -> None:
# Line breaks recognized by str.splitlines().
# Source: https://docs.python.org/3/library/stdtypes.html#str.splitlines
line_breaks = {
"\n", # Line Feed
"\r", # Carriage Return
"\r\n", # Carriage Return + Line Feed
"\v", # Vertical Tab
"\f", # Form Feed
"\x1c", # File Separator
"\x1d", # Group Separator
"\x1e", # Record Separator
"\x85", # Next Line (NEL)
"\u2028", # Line Separator
"\u2029", # Paragraph Separator
}
# Test all line breaks
for lb in line_breaks:
input_string = f"Text{lb}"
expected_output = input_string.replace(lb, "\n")
assert Text.from_ansi(input_string).plain == expected_output
# Test string without trailing line break
input_string = "No trailing\nline break"
assert Text.from_ansi(input_string).plain == input_string
# Test empty string
input_string = ""
assert Text.from_ansi(input_string).plain == input_string

@kmvanbrunt kmvanbrunt force-pushed the remove_rich_patch_3.x branch from aeac8a9 to 3648426 Compare April 13, 2026 15:25
@kmvanbrunt kmvanbrunt merged commit c217d33 into 3.x Apr 13, 2026
23 of 28 checks passed
@kmvanbrunt kmvanbrunt deleted the remove_rich_patch_3.x branch April 13, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant