Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlatr authored Dec 5, 2024
1 parent 38231e3 commit e29b7db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pydoctor/epydoc2stan.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def reportErrors(obj: model.Documentable, errs: Sequence[ParseError], section:st
section=section
)

def _objclass_for_docstring_parsing(obj: model.Documentable) -> ObjClass | None:
def _objclass(obj: model.Documentable) -> ObjClass | None:
# There is only 4 main kinds of objects
if isinstance(obj, model.Module):
return 'module'
Expand Down Expand Up @@ -617,7 +617,7 @@ def parse_docstring(

# fetch the parser function
try:
parser = get_parser_by_name(docformat, _objclass_for_docstring_parsing(obj))
parser = get_parser_by_name(docformat, _objclass(obj))
except (ImportError, AttributeError) as e:
_err = 'Error trying to fetch %r parser:\n\n %s: %s\n\nUsing plain text formatting only.'%(

Check warning on line 622 in pydoctor/epydoc2stan.py

View check run for this annotation

Codecov / codecov/patch

pydoctor/epydoc2stan.py#L621-L622

Added lines #L621 - L622 were not covered by tests
docformat, e.__class__.__name__, e)
Expand Down
6 changes: 3 additions & 3 deletions pydoctor/napoleon/docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def __init__(self, docstring: Union[str, List[str]],
The docstring to parse, given either as a string or split into
individual lines.
what:
String representing the type of object we're documenting.
Optional string representing the type of object we're documenting.
process_type_fields: bool
Whether to process the type fields or to leave them untouched (default) in order to be processed later.
Value ``process_type_fields=False`` is currently only used in the tests.
Expand Down Expand Up @@ -1067,10 +1067,10 @@ def _parse_attribute_docstring(self) -> List[str]:
# TODO: add 'vartype' and 'kwtype' as aliases of 'type' and use them here to output
# the most correct reStructuredText.
def _parse_attributes_section(self, section: str) -> List[str]:
fieldname = 'var' if self._what == 'module' else 'ivar'
fieldtag = 'var' if self._what == 'module' else 'ivar'
lines = []
for f in self._consume_fields():
field = f":{fieldname} {f.name}: "
field = f":{fieldtag} {f.name}: "
lines.extend(self._format_block(field, f.content))
if f.type:
lines.append(f":type {f.name}: {self._convert_type(f.type, lineno=f.lineno)}")
Expand Down
32 changes: 20 additions & 12 deletions pydoctor/test/epydoc/test_google_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from pydoctor.test import NotFoundLinker
from pydoctor.model import Attribute, Class, Module, System, Function
from pydoctor.stanutils import flatten
from pydoctor.epydoc2stan import _objclass_for_docstring_parsing
from pydoctor.epydoc2stan import _objclass

from pydoctor.epydoc.markup.google import get_parser as get_google_parser
from pydoctor.epydoc.markup.numpy import get_parser as get_numpy_parser

Expand All @@ -15,7 +16,8 @@ def test_get_google_parser_attribute(self) -> None:

obj = Attribute(system = System(), name='attr1')

parse_docstring = get_google_parser(_objclass_for_docstring_parsing(obj))
parse_docstring = get_google_parser(_objclass(obj))


docstring = """\
numpy.ndarray: super-dooper attribute"""
Expand All @@ -35,7 +37,8 @@ def test_get_google_parser_not_attribute(self) -> None:

obj = Function(system = System(), name='whatever')

parse_docstring = get_google_parser(_objclass_for_docstring_parsing(obj))
parse_docstring = get_google_parser(_objclass(obj))


docstring = """\
numpy.ndarray: super-dooper attribute"""
Expand All @@ -50,7 +53,8 @@ def test_get_numpy_parser_attribute(self) -> None:

obj = Attribute(system = System(), name='attr1')

parse_docstring = get_numpy_parser(_objclass_for_docstring_parsing(obj))
parse_docstring = get_numpy_parser(_objclass(obj))


docstring = """\
numpy.ndarray: super-dooper attribute"""
Expand All @@ -70,7 +74,8 @@ def test_get_numpy_parser_not_attribute(self) -> None:

obj = Function(system = System(), name='whatever')

parse_docstring = get_numpy_parser(_objclass_for_docstring_parsing(obj))
parse_docstring = get_numpy_parser(_objclass(obj))


docstring = """\
numpy.ndarray: super-dooper attribute"""
Expand All @@ -84,7 +89,8 @@ def test_get_parser_for_modules_does_not_generates_ivar(self) -> None:

obj = Module(system = System(), name='thing')

parse_docstring = get_google_parser(_objclass_for_docstring_parsing(obj))
parse_docstring = get_google_parser(_objclass(obj))


docstring = """\
Attributes:
Expand All @@ -94,14 +100,15 @@ def test_get_parser_for_modules_does_not_generates_ivar(self) -> None:

errors: List[ParseError] = []
parsed_doc = parse_docstring(docstring, errors)
fields_names = [f.tag() for f in parsed_doc.fields]
assert fields_names == ['var', 'var']
assert [f.tag() for f in parsed_doc.fields] == ['var', 'var']


def test_get_parser_for_classes_generates_ivar(self) -> None:

obj = Class(system = System(), name='thing')

parse_docstring = get_google_parser(_objclass_for_docstring_parsing(obj))
parse_docstring = get_google_parser(_objclass(obj))


docstring = """\
Attributes:
Expand All @@ -111,16 +118,17 @@ def test_get_parser_for_classes_generates_ivar(self) -> None:

errors: List[ParseError] = []
parsed_doc = parse_docstring(docstring, errors)
fields_names = [f.tag() for f in parsed_doc.fields]
assert fields_names == ['ivar', 'ivar']
assert [f.tag() for f in parsed_doc.fields] == ['ivar', 'ivar']


class TestWarnings(TestCase):

def test_warnings(self) -> None:

obj = Function(system = System(), name='func')

parse_docstring = get_numpy_parser(_objclass_for_docstring_parsing(obj))
parse_docstring = get_numpy_parser(_objclass(obj))


docstring = """
Description of the function.
Expand Down

0 comments on commit e29b7db

Please sign in to comment.