Merge pull request #7358 from tk0miya/refactor_autodoc

refactor: autodoc: Remove needless spaces from blank line
This commit is contained in:
Takeshi KOMIYA 2020-03-22 17:55:32 +09:00 committed by GitHub
commit 91a22a3ecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 252 additions and 249 deletions

View File

@ -270,7 +270,10 @@ class Documenter:
def add_line(self, line: str, source: str, *lineno: int) -> None:
"""Append one line of generated reST to the output."""
self.directive.result.append(self.indent + line, source, *lineno)
if line.strip(): # not a blank line
self.directive.result.append(self.indent + line, source, *lineno)
else:
self.directive.result.append('', source, *lineno)
def resolve_name(self, modname: str, parents: Any, path: str, base: Any
) -> Tuple[str, List[str]]:

View File

@ -361,7 +361,7 @@ def test_new_documenter(app):
' :module: target',
'',
' documentation for the integer',
' '
'',
]
@ -420,7 +420,7 @@ def test_py_module(app, warning):
' :module: target',
'',
' Function.',
' '
'',
]
assert ("don't know which module to import for autodocumenting 'Class.meth'"
not in warning.getvalue())
@ -435,7 +435,7 @@ def test_autodoc_decorator(app):
' :module: target.decorator',
'',
' docstring for deco1',
' '
'',
]
actual = do_autodoc(app, 'decorator', 'target.decorator.deco2')
@ -445,7 +445,7 @@ def test_autodoc_decorator(app):
' :module: target.decorator',
'',
' docstring for deco2',
' '
'',
]
@ -458,7 +458,7 @@ def test_autodoc_exception(app):
' :module: target',
'',
' My custom exception.',
' '
'',
]
@ -726,7 +726,7 @@ def test_autodoc_subclass_of_builtin_class(app):
' :module: target',
'',
' Docstring.',
' '
'',
]
@ -740,23 +740,23 @@ def test_autodoc_inner_class(app):
' :module: target',
'',
' Foo',
' ',
' ',
'',
'',
' .. py:class:: Outer.Inner',
' :module: target',
' ',
'',
' Foo',
' ',
' ',
'',
'',
' .. py:method:: Outer.Inner.meth()',
' :module: target',
' ',
'',
' Foo',
' ',
' ',
'',
'',
' .. py:attribute:: Outer.factory',
' :module: target',
' ',
'',
' alias of :class:`builtins.dict`'
]
@ -767,13 +767,13 @@ def test_autodoc_inner_class(app):
' :module: target.Outer',
'',
' Foo',
' ',
' ',
'',
'',
' .. py:method:: Inner.meth()',
' :module: target.Outer',
' ',
'',
' Foo',
' ',
'',
]
options['show-inheritance'] = True
@ -785,7 +785,7 @@ def test_autodoc_inner_class(app):
' Bases: :class:`target.Outer.Inner`',
'',
' InnerChild docstring',
' '
'',
]
@ -799,7 +799,7 @@ def test_autodoc_classmethod(app):
' :classmethod:',
'',
' Inherited class method.',
' '
'',
]
@ -813,7 +813,7 @@ def test_autodoc_staticmethod(app):
' :staticmethod:',
'',
' Inherited static method.',
' '
'',
]
@ -827,19 +827,19 @@ def test_autodoc_descriptor(app):
'.. py:class:: Class',
' :module: target.descriptor',
'',
' ',
'',
' .. py:attribute:: Class.descr',
' :module: target.descriptor',
' ',
'',
' Descriptor instance docstring.',
' ',
' ',
'',
'',
' .. py:method:: Class.prop',
' :module: target.descriptor',
' :property:',
' ',
'',
' Property.',
' '
''
]
@ -854,7 +854,7 @@ def test_autodoc_c_module(app):
" Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.",
' When the time tuple is not present, current time as returned by localtime()',
' is used.',
' '
'',
]
@ -946,7 +946,7 @@ def test_autodoc_module_scope(app):
' :value: <_io.StringIO object>',
'',
' should be documented as well - süß',
' '
'',
]
@ -962,7 +962,7 @@ def test_autodoc_class_scope(app):
' :value: <_io.StringIO object>',
'',
' should be documented as well - süß',
' '
'',
]
@ -976,16 +976,16 @@ def test_class_attributes(app):
'.. py:class:: AttCls',
' :module: target',
'',
' ',
'',
' .. py:attribute:: AttCls.a1',
' :module: target',
' :value: hello world',
' ',
' ',
'',
'',
' .. py:attribute:: AttCls.a2',
' :module: target',
' :value: None',
' '
''
]
@ -999,43 +999,43 @@ def test_instance_attributes(app):
' :module: target',
'',
' Class with documented class and instance attributes.',
' ',
' ',
'',
'',
' .. py:attribute:: InstAttCls.ca1',
' :module: target',
" :value: 'a'",
' ',
'',
' Doc comment for class attribute InstAttCls.ca1.',
' It can have multiple lines.',
' ',
' ',
'',
'',
' .. py:attribute:: InstAttCls.ca2',
' :module: target',
" :value: 'b'",
' ',
'',
' Doc comment for InstAttCls.ca2. One line only.',
' ',
' ',
'',
'',
' .. py:attribute:: InstAttCls.ca3',
' :module: target',
" :value: 'c'",
' ',
'',
' Docstring for class attribute InstAttCls.ca3.',
' ',
' ',
'',
'',
' .. py:attribute:: InstAttCls.ia1',
' :module: target',
' :value: None',
' ',
'',
' Doc comment for instance attribute InstAttCls.ia1',
' ',
' ',
'',
'',
' .. py:attribute:: InstAttCls.ia2',
' :module: target',
' :value: None',
' ',
'',
' Docstring for instance attribute InstAttCls.ia2.',
' '
''
]
# pick up arbitrary attributes
@ -1047,22 +1047,22 @@ def test_instance_attributes(app):
' :module: target',
'',
' Class with documented class and instance attributes.',
' ',
' ',
'',
'',
' .. py:attribute:: InstAttCls.ca1',
' :module: target',
" :value: 'a'",
' ',
'',
' Doc comment for class attribute InstAttCls.ca1.',
' It can have multiple lines.',
' ',
' ',
'',
'',
' .. py:attribute:: InstAttCls.ia1',
' :module: target',
' :value: None',
' ',
'',
' Doc comment for instance attribute InstAttCls.ia1',
' '
''
]
@ -1079,30 +1079,30 @@ def test_slots(app):
'.. py:class:: Bar()',
' :module: target.slots',
'',
' ',
'',
' .. py:attribute:: Bar.attr1',
' :module: target.slots',
' ',
'',
' docstring of attr1',
' ',
' ',
'',
'',
' .. py:attribute:: Bar.attr2',
' :module: target.slots',
' ',
'',
' docstring of instance attr2',
' ',
' ',
'',
'',
' .. py:attribute:: Bar.attr3',
' :module: target.slots',
' ',
'',
'',
'.. py:class:: Foo',
' :module: target.slots',
'',
' ',
'',
' .. py:attribute:: Foo.attr',
' :module: target.slots',
' ',
'',
]
@ -1117,39 +1117,39 @@ def test_enum_class(app):
' :module: target.enum',
'',
' this is enum class',
' ',
' ',
'',
'',
' .. py:method:: EnumCls.say_hello()',
' :module: target.enum',
' ',
'',
' a method says hello to you.',
' ',
' ',
'',
'',
' .. py:attribute:: EnumCls.val1',
' :module: target.enum',
' :value: 12',
' ',
'',
' doc for val1',
' ',
' ',
'',
'',
' .. py:attribute:: EnumCls.val2',
' :module: target.enum',
' :value: 23',
' ',
'',
' doc for val2',
' ',
' ',
'',
'',
' .. py:attribute:: EnumCls.val3',
' :module: target.enum',
' :value: 34',
' ',
'',
' doc for val3',
' ',
' ',
'',
'',
' .. py:attribute:: EnumCls.val4',
' :module: target.enum',
' :value: 34',
' '
''
]
# checks for an attribute of EnumClass
@ -1161,7 +1161,7 @@ def test_enum_class(app):
' :value: 12',
'',
' doc for val1',
' '
''
]
@ -1178,19 +1178,19 @@ def test_descriptor_class(app):
' :module: target.descriptor',
'',
' Descriptor class docstring.',
' ',
' ',
'',
'',
' .. py:method:: CustomDataDescriptor.meth()',
' :module: target.descriptor',
' ',
'',
' Function.',
' ',
'',
'',
'.. py:class:: CustomDataDescriptor2(doc)',
' :module: target.descriptor',
'',
' Descriptor class with custom metaclass docstring.',
' '
'',
]
@ -1203,7 +1203,7 @@ def test_autofunction_for_callable(app):
' :module: target.callable',
'',
' A callable object that behaves like a function.',
' '
'',
]
@ -1216,7 +1216,7 @@ def test_autofunction_for_method(app):
' :module: target.callable',
'',
' docstring of Callable.method().',
' '
'',
]
@ -1233,39 +1233,39 @@ def test_abstractmethods():
'.. py:class:: Base',
' :module: target.abstractmethods',
'',
' ',
'',
' .. py:method:: Base.abstractmeth()',
' :module: target.abstractmethods',
' :abstractmethod:',
' ',
' ',
'',
'',
' .. py:method:: Base.classmeth()',
' :module: target.abstractmethods',
' :abstractmethod:',
' :classmethod:',
' ',
' ',
'',
'',
' .. py:method:: Base.coroutinemeth()',
' :module: target.abstractmethods',
' :abstractmethod:',
' :async:',
' ',
' ',
'',
'',
' .. py:method:: Base.meth()',
' :module: target.abstractmethods',
' ',
' ',
'',
'',
' .. py:method:: Base.prop',
' :module: target.abstractmethods',
' :abstractmethod:',
' :property:',
' ',
' ',
'',
'',
' .. py:method:: Base.staticmeth()',
' :module: target.abstractmethods',
' :abstractmethod:',
' :staticmethod:',
' '
'',
]
@ -1282,25 +1282,25 @@ def test_partialfunction():
' :module: target.partialfunction',
'',
' docstring of func1',
' ',
'',
'',
'.. py:function:: func2(b, c)',
' :module: target.partialfunction',
'',
' docstring of func1',
' ',
'',
'',
'.. py:function:: func3(c)',
' :module: target.partialfunction',
'',
' docstring of func3',
' ',
'',
'',
'.. py:function:: func4()',
' :module: target.partialfunction',
'',
' docstring of func3',
' '
'',
]
@ -1328,7 +1328,7 @@ def test_bound_method():
' :module: target.bound_method',
'',
' Method docstring',
' ',
'',
]
@ -1350,29 +1350,29 @@ def test_coroutine():
'.. py:class:: AsyncClass',
' :module: target.coroutine',
'',
' ',
'',
' .. py:method:: AsyncClass.do_coroutine()',
' :module: target.coroutine',
' :async:',
' ',
'',
' A documented coroutine function',
' ',
' ',
'',
'',
' .. py:method:: AsyncClass.do_coroutine2()',
' :module: target.coroutine',
' :async:',
' :classmethod:',
' ',
'',
' A documented coroutine classmethod',
' ',
' ',
'',
'',
' .. py:method:: AsyncClass.do_coroutine3()',
' :module: target.coroutine',
' :async:',
' :staticmethod:',
' ',
'',
' A documented coroutine staticmethod',
' ',
'',
]
@ -1384,21 +1384,21 @@ def test_partialmethod(app):
' :module: target.partialmethod',
'',
' An example for partialmethod.',
' ',
'',
' refs: https://docs.python.jp/3/library/functools.html#functools.partialmethod',
' ',
' ',
'',
'',
' .. py:method:: Cell.set_alive()',
' :module: target.partialmethod',
' ',
'',
' Make a cell alive.',
' ',
' ',
'',
'',
' .. py:method:: Cell.set_state(state)',
' :module: target.partialmethod',
' ',
'',
' Update state of cell to *state*.',
' ',
'',
]
options = {"members": None}
@ -1414,25 +1414,25 @@ def test_partialmethod_undoc_members(app):
' :module: target.partialmethod',
'',
' An example for partialmethod.',
' ',
'',
' refs: https://docs.python.jp/3/library/functools.html#functools.partialmethod',
' ',
' ',
'',
'',
' .. py:method:: Cell.set_alive()',
' :module: target.partialmethod',
' ',
'',
' Make a cell alive.',
' ',
' ',
'',
'',
' .. py:method:: Cell.set_dead()',
' :module: target.partialmethod',
' ',
' ',
'',
'',
' .. py:method:: Cell.set_state(state)',
' :module: target.partialmethod',
' ',
'',
' Update state of cell to *state*.',
' ',
'',
]
options = {"members": None,
@ -1455,48 +1455,48 @@ def test_autodoc_typed_instance_variables(app):
'.. py:class:: Class()',
' :module: target.typed_vars',
'',
' ',
'',
' .. py:attribute:: Class.attr1',
' :module: target.typed_vars',
' :type: int',
' :value: 0',
' ',
' ',
'',
'',
' .. py:attribute:: Class.attr2',
' :module: target.typed_vars',
' :type: int',
' :value: None',
' ',
' ',
'',
'',
' .. py:attribute:: Class.attr3',
' :module: target.typed_vars',
' :type: int',
' :value: 0',
' ',
' ',
'',
'',
' .. py:attribute:: Class.attr4',
' :module: target.typed_vars',
' :type: int',
' :value: None',
' ',
'',
' attr4',
' ',
' ',
'',
'',
' .. py:attribute:: Class.attr5',
' :module: target.typed_vars',
' :type: int',
' :value: None',
' ',
'',
' attr5',
' ',
' ',
'',
'',
' .. py:attribute:: Class.attr6',
' :module: target.typed_vars',
' :type: int',
' :value: None',
' ',
'',
' attr6',
' ',
'',
'',
'.. py:data:: attr1',
' :module: target.typed_vars',
@ -1504,7 +1504,7 @@ def test_autodoc_typed_instance_variables(app):
" :value: ''",
'',
' attr1',
' ',
'',
'',
'.. py:data:: attr2',
' :module: target.typed_vars',
@ -1512,7 +1512,7 @@ def test_autodoc_typed_instance_variables(app):
' :value: None',
'',
' attr2',
' ',
'',
'',
'.. py:data:: attr3',
' :module: target.typed_vars',
@ -1520,7 +1520,7 @@ def test_autodoc_typed_instance_variables(app):
" :value: ''",
'',
' attr3',
' '
'',
]
@ -1538,7 +1538,7 @@ def test_autodoc_Annotated(app):
' :module: target.annotated',
'',
' docstring',
' '
'',
]
@ -1557,7 +1557,7 @@ def test_autodoc_for_egged_code(app):
' :value: 1',
'',
' constant on sample.py',
' ',
'',
'',
'.. py:function:: hello(s)',
' :module: sample',
@ -1580,7 +1580,7 @@ def test_singledispatch():
' :module: target.singledispatch',
'',
' A function for general use.',
' '
'',
]
@ -1599,13 +1599,13 @@ def test_singledispatchmethod():
' :module: target.singledispatchmethod',
'',
' docstring',
' ',
' ',
'',
'',
' .. py:method:: Foo.meth(arg, kwarg=None)',
' Foo.meth(arg: int, kwarg=None)',
' Foo.meth(arg: str, kwarg=None)',
' :module: target.singledispatchmethod',
' ',
'',
' A method for general use.',
' '
'',
]

View File

@ -31,49 +31,49 @@ def test_autoclass_content_class(app):
' :module: target.autoclass_content',
'',
' A class having no __init__, no __new__',
' ',
'',
'',
'.. py:class:: B()',
' :module: target.autoclass_content',
'',
' A class having __init__(no docstring), no __new__',
' ',
'',
'',
'.. py:class:: C()',
' :module: target.autoclass_content',
'',
' A class having __init__, no __new__',
' ',
'',
'',
'.. py:class:: D',
' :module: target.autoclass_content',
'',
' A class having no __init__, __new__(no docstring)',
' ',
'',
'',
'.. py:class:: E',
' :module: target.autoclass_content',
'',
' A class having no __init__, __new__',
' ',
'',
'',
'.. py:class:: F()',
' :module: target.autoclass_content',
'',
' A class having both __init__ and __new__',
' ',
'',
'',
'.. py:class:: G()',
' :module: target.autoclass_content',
'',
' A class inherits __init__ without docstring.',
' ',
'',
'',
'.. py:class:: H()',
' :module: target.autoclass_content',
'',
' A class inherits __new__ without docstring.',
' '
'',
]
@ -91,49 +91,49 @@ def test_autoclass_content_init(app):
' :module: target.autoclass_content',
'',
' A class having no __init__, no __new__',
' ',
'',
'',
'.. py:class:: B()',
' :module: target.autoclass_content',
'',
' A class having __init__(no docstring), no __new__',
' ',
'',
'',
'.. py:class:: C()',
' :module: target.autoclass_content',
'',
' __init__ docstring',
' ',
'',
'',
'.. py:class:: D',
' :module: target.autoclass_content',
'',
' A class having no __init__, __new__(no docstring)',
' ',
'',
'',
'.. py:class:: E',
' :module: target.autoclass_content',
'',
' __new__ docstring',
' ',
'',
'',
'.. py:class:: F()',
' :module: target.autoclass_content',
'',
' __init__ docstring',
' ',
'',
'',
'.. py:class:: G()',
' :module: target.autoclass_content',
'',
' __init__ docstring',
' ',
'',
'',
'.. py:class:: H()',
' :module: target.autoclass_content',
'',
' __new__ docstring',
' '
'',
]
@ -151,59 +151,59 @@ def test_autoclass_content_both(app):
' :module: target.autoclass_content',
'',
' A class having no __init__, no __new__',
' ',
'',
'',
'.. py:class:: B()',
' :module: target.autoclass_content',
'',
' A class having __init__(no docstring), no __new__',
' ',
'',
'',
'.. py:class:: C()',
' :module: target.autoclass_content',
'',
' A class having __init__, no __new__',
' ',
'',
' __init__ docstring',
' ',
'',
'',
'.. py:class:: D',
' :module: target.autoclass_content',
'',
' A class having no __init__, __new__(no docstring)',
' ',
'',
'',
'.. py:class:: E',
' :module: target.autoclass_content',
'',
' A class having no __init__, __new__',
' ',
'',
' __new__ docstring',
' ',
'',
'',
'.. py:class:: F()',
' :module: target.autoclass_content',
'',
' A class having both __init__ and __new__',
' ',
'',
' __init__ docstring',
' ',
'',
'',
'.. py:class:: G()',
' :module: target.autoclass_content',
'',
' A class inherits __init__ without docstring.',
' ',
'',
' __init__ docstring',
' ',
'',
'',
'.. py:class:: H()',
' :module: target.autoclass_content',
'',
' A class inherits __new__ without docstring.',
' ',
'',
' __new__ docstring',
' '
'',
]
@ -217,7 +217,7 @@ def test_autodoc_inherit_docstrings(app):
' :module: target.inheritance',
'',
' Inherited function.',
' '
'',
]
# disable autodoc_inherit_docstrings
@ -240,38 +240,38 @@ def test_autodoc_docstring_signature(app):
'.. py:class:: DocstringSig',
' :module: target',
'',
' ',
'',
' .. py:method:: DocstringSig.meth(FOO, BAR=1) -> BAZ',
' :module: target',
' ',
'',
' First line of docstring',
' ',
'',
' rest of docstring',
' ',
' ',
'',
'',
' .. py:method:: DocstringSig.meth2()',
' :module: target',
' ',
'',
' First line, no signature',
' Second line followed by indentation::',
' ',
'',
' indented line',
' ',
' ',
'',
'',
' .. py:method:: DocstringSig.prop1',
' :module: target',
' :property:',
' ',
'',
' First line of docstring',
' ',
' ',
'',
'',
' .. py:method:: DocstringSig.prop2',
' :module: target',
' :property:',
' ',
'',
' First line of docstring',
' Second line of docstring',
' '
'',
]
# disable autodoc_docstring_signature
@ -282,41 +282,41 @@ def test_autodoc_docstring_signature(app):
'.. py:class:: DocstringSig',
' :module: target',
'',
' ',
'',
' .. py:method:: DocstringSig.meth()',
' :module: target',
' ',
'',
' meth(FOO, BAR=1) -> BAZ',
' First line of docstring',
' ',
'',
' rest of docstring',
' ',
' ',
' ',
'',
'',
'',
' .. py:method:: DocstringSig.meth2()',
' :module: target',
' ',
'',
' First line, no signature',
' Second line followed by indentation::',
' ',
'',
' indented line',
' ',
' ',
'',
'',
' .. py:method:: DocstringSig.prop1',
' :module: target',
' :property:',
' ',
'',
' DocstringSig.prop1(self)',
' First line of docstring',
' ',
' ',
'',
'',
' .. py:method:: DocstringSig.prop2',
' :module: target',
' :property:',
' ',
'',
' First line of docstring',
' Second line of docstring',
' '
'',
]
@ -397,13 +397,13 @@ def test_autoclass_content_and_docstring_signature_both(app):
' :module: target.docstring_signature',
'',
' B(foo, bar, baz)',
' ',
'',
'',
'.. py:class:: C(foo, bar)',
' :module: target.docstring_signature',
'',
' C(foo, bar, baz)',
' ',
'',
'',
'.. py:class:: D(foo, bar, baz)',
' :module: target.docstring_signature',
@ -439,25 +439,25 @@ def test_mocked_module_imports(app, warning):
' :module: target.need_mocks',
'',
' TestAutodoc docstring.',
' ',
' ',
'',
'',
' .. py:method:: TestAutodoc.decoratedMethod()',
' :module: target.need_mocks',
' ',
'',
' TestAutodoc::decoratedMethod docstring',
' ',
'',
'',
'.. py:function:: decoratedFunction()',
' :module: target.need_mocks',
'',
' decoratedFunction docstring',
' ',
'',
'',
'.. py:function:: func(arg: missing_module.Class)',
' :module: target.need_mocks',
'',
' a function takes mocked object as an argument',
' '
'',
]
assert warning.getvalue() == ''
@ -476,22 +476,22 @@ def test_autodoc_typehints_signature(app):
'.. py:class:: Math(s: str, o: object = None)',
' :module: target.typehints',
'',
' ',
'',
' .. py:method:: Math.decr(a: int, b: int = 1) -> int',
' :module: target.typehints',
' ',
' ',
'',
'',
' .. py:method:: Math.horse(a: str, b: int) -> None',
' :module: target.typehints',
' ',
' ',
'',
'',
' .. py:method:: Math.incr(a: int, b: int = 1) -> int',
' :module: target.typehints',
' ',
' ',
'',
'',
' .. py:method:: Math.nothing() -> None',
' :module: target.typehints',
' ',
'',
'',
'.. py:function:: complex_func(arg1: str, arg2: List[int], arg3: Tuple[int, '
'Union[str, Unknown]] = None, *args: str, **kwargs: str) -> None',
@ -526,22 +526,22 @@ def test_autodoc_typehints_none(app):
'.. py:class:: Math(s, o=None)',
' :module: target.typehints',
'',
' ',
'',
' .. py:method:: Math.decr(a, b=1)',
' :module: target.typehints',
' ',
' ',
'',
'',
' .. py:method:: Math.horse(a, b)',
' :module: target.typehints',
' ',
' ',
'',
'',
' .. py:method:: Math.incr(a, b=1)',
' :module: target.typehints',
' ',
' ',
'',
'',
' .. py:method:: Math.nothing()',
' :module: target.typehints',
' ',
'',
'',
'.. py:function:: complex_func(arg1, arg2, arg3=None, *args, **kwargs)',
' :module: target.typehints',

View File

@ -44,7 +44,7 @@ def test_cut_lines(app):
' :module: target.process_docstring',
'',
' second line',
' '
'',
]
@ -60,7 +60,7 @@ def test_between(app):
' :module: target.process_docstring',
'',
' second line',
' '
'',
]
@ -77,5 +77,5 @@ def test_between_exclude(app):
'',
' first line',
' third line',
' '
'',
]

View File

@ -40,7 +40,7 @@ def test_private_field_and_private_members(app):
' :module: target.private',
'',
' private_function is a docstring().',
' ',
'',
' :meta private:',
' '
'',
]