Skip to content

Commit

Permalink
Fix for single line docstrings (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Colvin <[email protected]>
  • Loading branch information
alexmojaki and samuelcolvin authored Nov 15, 2024
1 parent be12278 commit ee6bee2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pytest_examples/find_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def find_examples(*paths: str | Path, skip: bool = False) -> Iterable[CodeExampl
group = uuid4()
if path.suffix == '.py':
code = path.read_text('utf-8')
for m_docstring in re.finditer(r'(^ *)(r?""")(.+?)\1"""', code, flags=re.M | re.S):
for m_docstring in re.finditer(r'(^ *)(r?""")(.+?)"""', code, flags=re.M | re.S):
start_line = code[: m_docstring.start()].count('\n')
docstring = m_docstring.group(3)
index_offset = m_docstring.start() + len(m_docstring.group(1)) + len(m_docstring.group(2))
Expand Down
5 changes: 5 additions & 0 deletions tests/test_find_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def test_find_index_markdown(tmp_path):
def test_find_index_python(tmp_path):
# language=Python
code = '''
def foo():
"""Single line docstring"""
pass
def func_a():
"""
prefix.
Expand Down

0 comments on commit ee6bee2

Please sign in to comment.