Skip to content

Commit 9a292ae

Browse files
committed
Escape backslashes in generated docstrings
1 parent 889eabc commit 9a292ae

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

.generator/src/generator/formatter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ def header(self, text, level, raw=None):
168168
def docstring(text):
169169
if not text:
170170
return text
171-
return (
171+
converted = (
172172
m2r2.convert((text or "").replace("\\n", "\\\\n"), renderer=CustomRenderer())[1:-1]
173173
.replace("\\ ", " ")
174-
.replace("\\`", "\\\\`")
175174
.replace("\n\n\n", "\n\n")
176175
)
176+
return converted.replace("\\", "\\\\")
177177

178178

179179
def _merge_imports(a, b):

.generator/tests/test_formatter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import pytest
22
from collections import defaultdict
3-
from generator.formatter import _is_valid_identifier, format_data_with_schema
3+
from generator.formatter import _is_valid_identifier, docstring, format_data_with_schema
4+
5+
6+
class TestDocstring:
7+
def test_escapes_backslashes_for_python_string_literals(self):
8+
assert "``\\\\s``" in docstring(r"regex pattern like ``\s`` for spaces")
49

510

611
class TestIsValidIdentifier:

src/datadog_api_client/v1/api/logs_pipelines_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class LogsPipelinesApi:
3535
returned data to be configured before using in a request.**
3636
For example, if you are using the data returned from a
3737
request for another request body, and have a parsing rule
38-
that uses a regex pattern like ``\s`` for spaces, you will
38+
that uses a regex pattern like ``\\s`` for spaces, you will
3939
need to configure all escaped spaces as ``%{space}`` to use
4040
in the body data.
4141
"""

0 commit comments

Comments
 (0)