Skip to content

Commit 1641cae

Browse files
authored
Merge pull request #2943 from Textualize/clean-cached-hash
Clear hashed cache when clearing meta.
2 parents 610fd75 + 1a97825 commit 1641cae

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Fix pretty repr for `collections.deque` https://github.com/Textualize/rich/pull/2864
1616
- Thread used in progress.track will exit if an exception occurs in a generator https://github.com/Textualize/rich/pull/3402
1717
- Progress track thread is now a daemon thread https://github.com/Textualize/rich/pull/3402
18+
- Fixed cached hash preservation upon clearing meta and links https://github.com/Textualize/rich/issues/2942
1819

1920
### Changed
2021

rich/style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ def clear_meta_and_links(self) -> "Style":
663663
style._set_attributes = self._set_attributes
664664
style._link = None
665665
style._link_id = ""
666-
style._hash = self._hash
666+
style._hash = None
667667
style._null = False
668668
style._meta = None
669669
return style

tests/test_style.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,17 @@ def test_clear_meta_and_links():
251251
assert clear_style.bgcolor == Color.parse("black")
252252
assert clear_style.bold
253253
assert not clear_style.italic
254+
255+
256+
def test_clear_meta_and_links_clears_hash():
257+
"""Regression test for https://github.com/Textualize/rich/issues/2942."""
258+
259+
style = Style.parse("bold red on black link https://example.org") + Style.on(
260+
click="CLICK"
261+
)
262+
hash(style) # Force hash caching.
263+
264+
assert style._hash is not None
265+
266+
clear_style = style.clear_meta_and_links()
267+
assert clear_style._hash is None

0 commit comments

Comments
 (0)