Fix invalid escape sequences in docstrings causing `SyntaxWarning`
Description
Several docstrings in the rampy package include backslash-escaped parentheses (e.g. \( and \)) without being raw string literals, which triggers SyntaxWarning: invalid escape sequence '\(' at runtime.
Affected files & lines
-
baseline.py(line 161) -
filters.py(lines 44, 148) -
peak_area.py(line 54) -
peak_shapes.py(lines 27, 64, 105, 148) -
spectranization.py(line 265) -
tlcorrection.py(line 25)
Context & Impact
Although rampy itself may not run these warnings during its own test suite, any downstream project that depends on rampy will see these SyntaxWarnings “leak” into their console output (for example when running mypy), which is noisy.
Steps to reproduce
python -W default -m mypy your_project_using_rampy
Proposed solution Convert each affected docstring to a raw string literal. For example:
- """Formula used: \(y = a \cdot \exp(-\log(2) \cdot ((x-b)/c)^2)\)."""
+ r"""Formula used: \(y = a \cdot \exp(-\log(2) \cdot ((x-b)/c)^2)\)."""
This preserves the intended text while eliminating the warnings.
Full Output
rampy/src/rampy/baseline.py:161: SyntaxWarning: invalid escape sequence '\('
\(y = a \cdot \exp(-\log(2) \cdot ((x-b)/c)^2)\). Default is [1., 1., 1.].
rampy/src/rampy/filters.py:44: SyntaxWarning: invalid escape sequence '\('
produce smoother fits. Default is \(10^5\).
rampy/src/rampy/filters.py:148: SyntaxWarning: invalid escape sequence '\('
Default is \(10^5\).
rampy/src/rampy/peak_area.py:54: SyntaxWarning: invalid escape sequence '\('
\( \text{area} = \sqrt{\pi / \ln(2)} \cdot \text{amp} \cdot \text{HWHM} \).
rampy/src/rampy/peak_shapes.py:27: SyntaxWarning: invalid escape sequence '\('
Formula used: \( \text{amp} \cdot \exp(-\log(2) \cdot ((x - \text{freq}) / \text{HWHM})^2) \).
rampy/src/rampy/peak_shapes.py:64: SyntaxWarning: invalid escape sequence '\('
Formula used: \( \text{amp} / (1 + ((x - \text{freq}) / \text{HWHM})^2) \).
rampy/src/rampy/peak_shapes.py:105: SyntaxWarning: invalid escape sequence '\('
Formula used: \( (1 - L_{\text{ratio}}) \cdot \text{gaussian}(x, \text{amp}, \text{freq}, \text{HWHM}) +
rampy/src/rampy/peak_shapes.py:148: SyntaxWarning: invalid escape sequence '\('
Formula used: \( a_0 / ((1 + ((x - a_1) / a_2)^2 \cdot (2^{(1/a_3)} - 1))^{a_3}) \).
rampy/src/rampy/spectranization.py:265: SyntaxWarning: invalid escape sequence '\('
The centroid is calculated as \( \text{centroid} = \sum(y / \sum(y) \cdot x) \).
rampy/src/rampy/tlcorrection.py:25: SyntaxWarning: invalid escape sequence '\('
- 'long': Default equation from Galeener and Sen (1978) with a \(v_0^3\) coefficient correction.
OK thanks for pointing that. I will do some tests and fix it.