Repository: Textualize/rich (python)

Issue:
[BUG] Style.clear_meta_and_links should reset hash
The hash of a `Style` instance depends on `_meta` and `_link`:

https://github.com/Textualize/rich/blob/6d30ad0f30028210124c149811cbbe2b183711f9/rich/style.py#L432-L445

So, when the link and meta are cleared with the method `Style.clear_meta_and_links`, the cached hash should be cleared:

https://github.com/Textualize/rich/blob/6d30ad0f30028210124c149811cbbe2b183711f9/rich/style.py#L664-L668

Pull request description:
Clear hashed cache when clearing meta.
This fixes #2942.

## Type of changes

- [x] Bug fix
- [ ] New feature
- [ ] Documentation / docstrings
- [ ] Tests
- [ ] Other

## Checklist

- [x] I've run the latest [black](https://github.com/psf/black) with default args on new code.
- [x] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
- [x] I've added tests for new code.
- [x] I accept that @willmcgugan may be pedantic in the code review.



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e47aa39a..6911c40c 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 313c8894..262fd6ec 100644
--- a/rich/style.py
+++ b/rich/style.py
@@ -663,7 +663,7 @@ class 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


Test patch:
diff --git a/tests/test_style.py b/tests/test_style.py
index b5c01729..84a65a67 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