Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docstring_parser/epydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _clean_str(string: str) -> T.Optional[str]:
return None


def parse(text: str) -> Docstring:
def parse(text: T.Optional[str]) -> Docstring:
"""Parse the epydoc-style docstring into its components.

:returns: parsed docstring
Expand Down
4 changes: 2 additions & 2 deletions docstring_parser/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def add_section(self, section: Section):
self.sections[section.title] = section
self._setup()

def parse(self, text: str) -> Docstring:
def parse(self, text: T.Optional[str]) -> Docstring:
"""Parse the Google-style docstring into its components.

:returns: parsed docstring
Expand Down Expand Up @@ -293,7 +293,7 @@ def parse(self, text: str) -> Docstring:
return ret


def parse(text: str) -> Docstring:
def parse(text: T.Optional[str]) -> Docstring:
"""Parse the Google-style docstring into its components.

:returns: parsed docstring
Expand Down
4 changes: 2 additions & 2 deletions docstring_parser/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def add_section(self, section: Section):
self.sections[section.title] = section
self._setup()

def parse(self, text: str) -> Docstring:
def parse(self, text: T.Optional[str]) -> Docstring:
"""Parse the numpy-style docstring into its components.

:returns: parsed docstring
Expand Down Expand Up @@ -370,7 +370,7 @@ def parse(self, text: str) -> Docstring:
return ret


def parse(text: str) -> Docstring:
def parse(text: T.Optional[str]) -> Docstring:
"""Parse the numpy-style docstring into its components.

:returns: parsed docstring
Expand Down
4 changes: 3 additions & 1 deletion docstring_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
}


def parse(text: str, style: DocstringStyle = DocstringStyle.AUTO) -> Docstring:
def parse(
text: T.Optional[str], style: DocstringStyle = DocstringStyle.AUTO
) -> Docstring:
"""Parse the docstring into its components.

:param text: docstring text to parse
Expand Down
2 changes: 1 addition & 1 deletion docstring_parser/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _build_meta(args: T.List[str], desc: str) -> DocstringMeta:
return DocstringMeta(args=args, description=desc)


def parse(text: str) -> Docstring:
def parse(text: T.Optional[str]) -> Docstring:
"""Parse the ReST-style docstring into its components.

:returns: parsed docstring
Expand Down
5 changes: 4 additions & 1 deletion docstring_parser/tests/test_epydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
@pytest.mark.parametrize(
"source, expected",
[
pytest.param(None, None, id="No __doc__"),
("", None),
("\n", None),
("Short description", "Short description"),
("\nShort description\n", "Short description"),
("\n Short description\n", "Short description"),
],
)
def test_short_description(source: str, expected: str) -> None:
def test_short_description(
source: T.Optional[str], expected: T.Optional[str]
) -> None:
"""Test parsing short description."""
docstring = parse(source)
assert docstring.short_description == expected
Expand Down
5 changes: 4 additions & 1 deletion docstring_parser/tests/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,17 @@ def test_google_parser_custom_sections_after() -> None:
@pytest.mark.parametrize(
"source, expected",
[
pytest.param(None, None, id="No __doc__"),
("", None),
("\n", None),
("Short description", "Short description"),
("\nShort description\n", "Short description"),
("\n Short description\n", "Short description"),
],
)
def test_short_description(source: str, expected: str) -> None:
def test_short_description(
source: T.Optional[str], expected: T.Optional[str]
) -> None:
"""Test parsing short description."""
docstring = parse(source)
assert docstring.short_description == expected
Expand Down
5 changes: 4 additions & 1 deletion docstring_parser/tests/test_numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
@pytest.mark.parametrize(
"source, expected",
[
pytest.param(None, None, id="No __doc__"),
("", None),
("\n", None),
("Short description", "Short description"),
("\nShort description\n", "Short description"),
("\n Short description\n", "Short description"),
],
)
def test_short_description(source: str, expected: str) -> None:
def test_short_description(
source: T.Optional[str], expected: T.Optional[str]
) -> None:
"""Test parsing short description."""
docstring = parse(source)
assert docstring.short_description == expected
Expand Down
24 changes: 24 additions & 0 deletions docstring_parser/tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
"""Tests for generic docstring routines."""

import typing as T

import pytest
from docstring_parser.common import DocstringStyle, ParseError
from docstring_parser.parser import parse


@pytest.mark.parametrize(
"source, expected",
[
pytest.param(None, None, id="No __doc__"),
("", None),
("\n", None),
("Short description", "Short description"),
("\nShort description\n", "Short description"),
("\n Short description\n", "Short description"),
],
)
def test_short_description(
source: T.Optional[str], expected: T.Optional[str]
) -> None:
"""Test parsing short description."""
docstring = parse(source)
assert docstring.short_description == expected
assert docstring.description == expected
assert docstring.long_description is None
assert not docstring.meta


def test_rest() -> None:
"""Test ReST-style parser autodetection."""
docstring = parse(
Expand Down
5 changes: 4 additions & 1 deletion docstring_parser/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
@pytest.mark.parametrize(
"source, expected",
[
pytest.param(None, None, id="No __doc__"),
("", None),
("\n", None),
("Short description", "Short description"),
("\nShort description\n", "Short description"),
("\n Short description\n", "Short description"),
],
)
def test_short_description(source: str, expected: str) -> None:
def test_short_description(
source: T.Optional[str], expected: T.Optional[str]
) -> None:
"""Test parsing short description."""
docstring = parse(source)
assert docstring.short_description == expected
Expand Down
Loading