Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix pretty repr for `collections.deque` https://github.com/Textualize/rich/pull/2864
- Thread used in progress.track will exit if an exception occurs in a generator https://github.com/Textualize/rich/pull/3402
- Progress track thread is now a daemon thread https://github.com/Textualize/rich/pull/3402
- Fixed cached hash preservation upon clearing meta and links https://github.com/Textualize/rich/issues/2942

### Changed

Expand Down
2 changes: 1 addition & 1 deletion rich/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def clear_meta_and_links(self) -> "Style":
style._set_attributes = self._set_attributes
style._link = None
style._link_id = ""
style._hash = self._hash
style._hash = None
style._null = False
style._meta = None
return style
Expand Down
14 changes: 14 additions & 0 deletions tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,17 @@ def test_clear_meta_and_links():
assert clear_style.bgcolor == Color.parse("black")
assert clear_style.bold
assert not clear_style.italic


def test_clear_meta_and_links_clears_hash():
"""Regression test for https://github.com/Textualize/rich/issues/2942."""

style = Style.parse("bold red on black link https://example.org") + Style.on(
click="CLICK"
)
hash(style) # Force hash caching.

assert style._hash is not None

clear_style = style.clear_meta_and_links()
assert clear_style._hash is None