diff --git a/src/evidently/descriptors/text_match.py b/src/evidently/descriptors/text_match.py index be1edb1ea8..905847d026 100644 --- a/src/evidently/descriptors/text_match.py +++ b/src/evidently/descriptors/text_match.py @@ -115,7 +115,12 @@ def exact_match(self, text: str, items: List[str]) -> bool: class TextMatch(Descriptor): - """ + # The docstring contains a regex example with `\b\d{3}-\d{3}-\d{4}\b`. The + # `r"..."` prefix only marks the *example* literal as raw — the docstring + # itself still parses every backslash, so `\d` triggers + # `SyntaxWarning: invalid escape sequence '\d'` on Python 3.12+. Marking the + # docstring itself raw silences the warning without changing rendered help. + r""" Unified text matching descriptor that handles all word/text matching scenarios. This descriptor replaces multiple legacy text matching features with a single, diff --git a/tests/future/descriptors/test_text_match.py b/tests/future/descriptors/test_text_match.py index 761f511ae8..7cb9f93c95 100644 --- a/tests/future/descriptors/test_text_match.py +++ b/tests/future/descriptors/test_text_match.py @@ -1,8 +1,25 @@ +import py_compile +import warnings + import pandas as pd import pytest from evidently.core.datasets import Dataset from evidently.descriptors import TextMatch +import evidently.descriptors.text_match as text_match_module + + +def test_text_match_module_compiles_without_syntax_warning(tmp_path): + # Regression: the TextMatch docstring contains an `r"\b\d{3}-..."` regex + # example, but the docstring itself wasn't raw, so `\d` triggered + # `SyntaxWarning: invalid escape sequence '\d'` on Python 3.12+. + # py_compile surfaces SyntaxWarnings as PyCompileErrors when warnings are + # promoted to errors, so this is a reliable check that doesn't depend on + # whether the module is already cached / imported elsewhere. + source_path = text_match_module.__file__ + with warnings.catch_warnings(): + warnings.simplefilter("error", SyntaxWarning) + py_compile.compile(source_path, cfile=str(tmp_path / "out.pyc"), doraise=True) @pytest.fixture