diff --git a/CHANGELOG.md b/CHANGELOG.md index e47aa39a1..6911c40c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/rich/style.py b/rich/style.py index 313c88949..262fd6eca 100644 --- a/rich/style.py +++ b/rich/style.py @@ -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 diff --git a/tests/test_style.py b/tests/test_style.py index b5c01729e..84a65a677 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -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