Merge branch '3.x'

This commit is contained in:
Takeshi KOMIYA 2020-05-02 10:43:10 +09:00
commit f82151bda5
12 changed files with 267 additions and 68 deletions

View File

@ -94,6 +94,8 @@ Features added
* #7543: html theme: Add top and bottom margins to tables
* C and C++: allow semicolon in the end of declarations.
* C++, parse parameterized noexcept specifiers.
* #7294: C++, parse expressions with user-defined literals.
* C++, parse trailing return types.
* #7143: py domain: Add ``:final:`` option to :rst:dir:`py:class:`,
:rst:dir:`py:exception:` and :rst:dir:`py:method:` directives
@ -105,9 +107,11 @@ Bugs fixed
* #6588: autodoc: Decorated inherited method has no documentation
* #7469: autodoc: The change of autodoc-process-docstring for variables is
cached unexpectedly
* #7559: autodoc: misdetects a sync function is async
* #7535: sphinx-autogen: crashes when custom template uses inheritance
* #7536: sphinx-autogen: crashes when template uses i18n feature
* #2785: html: Bad alignment of equation links
* #7581: napoleon: bad parsing of inline code in attribute docstrings
Testing
--------

View File

@ -132,8 +132,8 @@ a comma-separated list of group names.
.. testcode::
1+1 # this will give no output!
print 2+2 # this will give output
1+1 # this will give no output!
print(2+2) # this will give output
.. testoutput::
@ -161,7 +161,7 @@ a comma-separated list of group names.
.. testcode::
print 'Output text.'
print('Output text.')
.. testoutput::
:hide:
@ -328,7 +328,7 @@ The doctest extension uses the following configuration values:
Some documentation text.
>>> print 1
>>> print(1)
1
Some more documentation text.
@ -344,7 +344,7 @@ The doctest extension uses the following configuration values:
.. doctest::
>>> print 1
>>> print(1)
1
Some more documentation text.

View File

@ -31,7 +31,8 @@ from sphinx.util.cfamily import (
NoOldIdError, ASTBaseBase, verify_description_mode, StringifyTransform,
BaseParser, DefinitionError, UnsupportedMultiCharacterCharLiteral,
identifier_re, anon_identifier_re, integer_literal_re, octal_literal_re,
hex_literal_re, binary_literal_re, float_literal_re,
hex_literal_re, binary_literal_re, integers_literal_suffix_re,
float_literal_re, float_literal_suffix_re,
char_literal_re
)
from sphinx.util.docfields import Field, TypedField
@ -2076,12 +2077,14 @@ class DefinitionParser(BaseParser):
return ASTBooleanLiteral(True)
if self.skip_word('false'):
return ASTBooleanLiteral(False)
for regex in [float_literal_re, binary_literal_re, hex_literal_re,
pos = self.pos
if self.match(float_literal_re):
self.match(float_literal_suffix_re)
return ASTNumberLiteral(self.definition[pos:self.pos])
for regex in [binary_literal_re, hex_literal_re,
integer_literal_re, octal_literal_re]:
pos = self.pos
if self.match(regex):
while self.current_char in 'uUlLfF':
self.pos += 1
self.match(integers_literal_suffix_re)
return ASTNumberLiteral(self.definition[pos:self.pos])
string = self._parse_string()

View File

@ -34,7 +34,8 @@ from sphinx.util.cfamily import (
NoOldIdError, ASTBaseBase, ASTAttribute, verify_description_mode, StringifyTransform,
BaseParser, DefinitionError, UnsupportedMultiCharacterCharLiteral,
identifier_re, anon_identifier_re, integer_literal_re, octal_literal_re,
hex_literal_re, binary_literal_re, float_literal_re,
hex_literal_re, binary_literal_re, integers_literal_suffix_re,
float_literal_re, float_literal_suffix_re,
char_literal_re
)
from sphinx.util.docfields import Field, GroupedField
@ -296,6 +297,9 @@ T = TypeVar('T')
nested-name
"""
udl_identifier_re = re.compile(r'''(?x)
[a-zA-Z_][a-zA-Z0-9_]*\b # note, no word boundary in the beginning
''')
_string_re = re.compile(r"[LuU8]?('([^'\\]*(?:\\.[^'\\]*)*)'"
r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S)
_visibility_re = re.compile(r'\b(public|private|protected)\b')
@ -607,8 +611,7 @@ class ASTIdentifier(ASTBase):
reftype='identifier',
reftarget=targetText, modname=None,
classname=None)
key = symbol.get_lookup_key()
pnode['cpp:parent_key'] = key
pnode['cpp:parent_key'] = symbol.get_lookup_key()
if self.is_anon():
pnode += nodes.strong(text="[anonymous]")
else:
@ -624,6 +627,19 @@ class ASTIdentifier(ASTBase):
signode += nodes.strong(text="[anonymous]")
else:
signode += nodes.Text(self.identifier)
elif mode == 'udl':
# the target is 'operator""id' instead of just 'id'
assert len(prefix) == 0
assert len(templateArgs) == 0
assert not self.is_anon()
targetText = 'operator""' + self.identifier
pnode = addnodes.pending_xref('', refdomain='cpp',
reftype='identifier',
reftarget=targetText, modname=None,
classname=None)
pnode['cpp:parent_key'] = symbol.get_lookup_key()
pnode += nodes.Text(self.identifier)
signode += pnode
else:
raise Exception('Unknown description mode: %s' % mode)
@ -830,6 +846,7 @@ class ASTNumberLiteral(ASTLiteral):
return self.data
def get_id(self, version: int) -> str:
# TODO: floats should be mangled by writing the hex of the binary representation
return "L%sE" % self.data
def describe_signature(self, signode: TextElement, mode: str,
@ -874,6 +891,7 @@ class ASTCharLiteral(ASTLiteral):
return self.prefix + "'" + self.data + "'"
def get_id(self, version: int) -> str:
# TODO: the ID should be have L E around it
return self.type + str(self.value)
def describe_signature(self, signode: TextElement, mode: str,
@ -882,6 +900,26 @@ class ASTCharLiteral(ASTLiteral):
signode.append(nodes.Text(txt, txt))
class ASTUserDefinedLiteral(ASTLiteral):
def __init__(self, literal: ASTLiteral, ident: ASTIdentifier):
self.literal = literal
self.ident = ident
def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.literal) + transform(self.ident)
def get_id(self, version: int) -> str:
# mangle as if it was a function call: ident(literal)
return 'clL_Zli{}E{}E'.format(self.ident.get_id(version), self.literal.get_id(version))
def describe_signature(self, signode: TextElement, mode: str,
env: "BuildEnvironment", symbol: "Symbol") -> None:
self.literal.describe_signature(signode, mode, env, symbol)
self.ident.describe_signature(signode, "udl", env, "", "", symbol)
################################################################################
class ASTThisLiteral(ASTExpression):
def _stringify(self, transform: StringifyTransform) -> str:
return "this"
@ -1833,13 +1871,14 @@ class ASTNoexceptSpec(ASTBase):
class ASTParametersQualifiers(ASTBase):
def __init__(self, args: List[ASTFunctionParameter], volatile: bool, const: bool,
refQual: str, exceptionSpec: ASTNoexceptSpec, override: bool, final: bool,
initializer: str) -> None:
refQual: str, exceptionSpec: ASTNoexceptSpec, trailingReturn: "ASTType",
override: bool, final: bool, initializer: str) -> None:
self.args = args
self.volatile = volatile
self.const = const
self.refQual = refQual
self.exceptionSpec = exceptionSpec
self.trailingReturn = trailingReturn
self.override = override
self.final = final
self.initializer = initializer
@ -1894,6 +1933,9 @@ class ASTParametersQualifiers(ASTBase):
if self.exceptionSpec:
res.append(' ')
res.append(transform(self.exceptionSpec))
if self.trailingReturn:
res.append(' -> ')
res.append(transform(self.trailingReturn))
if self.final:
res.append(' final')
if self.override:
@ -1932,6 +1974,9 @@ class ASTParametersQualifiers(ASTBase):
if self.exceptionSpec:
signode += nodes.Text(' ')
self.exceptionSpec.describe_signature(signode, mode, env, symbol)
if self.trailingReturn:
signode += nodes.Text(' -> ')
self.trailingReturn.describe_signature(signode, mode, env, symbol)
if self.final:
_add_anno(signode, 'final')
if self.override:
@ -2141,6 +2186,10 @@ class ASTDeclarator(ASTBase):
def function_params(self) -> List[ASTFunctionParameter]:
raise NotImplementedError(repr(self))
@property
def trailingReturn(self) -> "ASTType":
raise NotImplementedError(repr(self))
def require_space_after_declSpecs(self) -> bool:
raise NotImplementedError(repr(self))
@ -2184,6 +2233,10 @@ class ASTDeclaratorNameParamQual(ASTDeclarator):
def function_params(self) -> List[ASTFunctionParameter]:
return self.paramQual.function_params
@property
def trailingReturn(self) -> "ASTType":
return self.paramQual.trailingReturn
# only the modifiers for a function, e.g.,
def get_modifiers_id(self, version: int) -> str:
# cv-qualifiers
@ -2301,6 +2354,10 @@ class ASTDeclaratorPtr(ASTDeclarator):
def function_params(self) -> List[ASTFunctionParameter]:
return self.next.function_params
@property
def trailingReturn(self) -> "ASTType":
return self.next.trailingReturn
def require_space_after_declSpecs(self) -> bool:
return self.next.require_space_after_declSpecs()
@ -2400,6 +2457,10 @@ class ASTDeclaratorRef(ASTDeclarator):
def function_params(self) -> List[ASTFunctionParameter]:
return self.next.function_params
@property
def trailingReturn(self) -> "ASTType":
return self.next.trailingReturn
def require_space_after_declSpecs(self) -> bool:
return self.next.require_space_after_declSpecs()
@ -2456,6 +2517,10 @@ class ASTDeclaratorParamPack(ASTDeclarator):
def function_params(self) -> List[ASTFunctionParameter]:
return self.next.function_params
@property
def trailingReturn(self) -> "ASTType":
return self.next.trailingReturn
def require_space_after_declSpecs(self) -> bool:
return False
@ -2512,6 +2577,10 @@ class ASTDeclaratorMemPtr(ASTDeclarator):
def function_params(self) -> List[ASTFunctionParameter]:
return self.next.function_params
@property
def trailingReturn(self) -> "ASTType":
return self.next.trailingReturn
def require_space_after_declSpecs(self) -> bool:
return True
@ -2600,6 +2669,10 @@ class ASTDeclaratorParen(ASTDeclarator):
def function_params(self) -> List[ASTFunctionParameter]:
return self.inner.function_params
@property
def trailingReturn(self) -> "ASTType":
return self.inner.trailingReturn
def require_space_after_declSpecs(self) -> bool:
return True
@ -2728,6 +2801,10 @@ class ASTType(ASTBase):
def function_params(self) -> List[ASTFunctionParameter]:
return self.decl.function_params
@property
def trailingReturn(self) -> "ASTType":
return self.decl.trailingReturn
def get_id(self, version: int, objectType: str = None,
symbol: "Symbol" = None) -> str:
if version == 1:
@ -2764,7 +2841,10 @@ class ASTType(ASTBase):
templ = symbol.declaration.templatePrefix
if templ is not None:
typeId = self.decl.get_ptr_suffix_id(version)
returnTypeId = self.declSpecs.get_id(version)
if self.trailingReturn:
returnTypeId = self.trailingReturn.get_id(version)
else:
returnTypeId = self.declSpecs.get_id(version)
res.append(typeId)
res.append(returnTypeId)
res.append(self.decl.get_param_id(version))
@ -4651,6 +4731,15 @@ class DefinitionParser(BaseParser):
# | boolean-literal -> "false" | "true"
# | pointer-literal -> "nullptr"
# | user-defined-literal
def _udl(literal: ASTLiteral) -> ASTLiteral:
if not self.match(udl_identifier_re):
return literal
# hmm, should we care if it's a keyword?
# it looks like GCC does not disallow keywords
ident = ASTIdentifier(self.matched_text)
return ASTUserDefinedLiteral(literal, ident)
self.skip_ws()
if self.skip_word('nullptr'):
return ASTPointerLiteral()
@ -4658,31 +4747,40 @@ class DefinitionParser(BaseParser):
return ASTBooleanLiteral(True)
if self.skip_word('false'):
return ASTBooleanLiteral(False)
for regex in [float_literal_re, binary_literal_re, hex_literal_re,
pos = self.pos
if self.match(float_literal_re):
hasSuffix = self.match(float_literal_suffix_re)
floatLit = ASTNumberLiteral(self.definition[pos:self.pos])
if hasSuffix:
return floatLit
else:
return _udl(floatLit)
for regex in [binary_literal_re, hex_literal_re,
integer_literal_re, octal_literal_re]:
pos = self.pos
if self.match(regex):
while self.current_char in 'uUlLfF':
self.pos += 1
return ASTNumberLiteral(self.definition[pos:self.pos])
hasSuffix = self.match(integers_literal_suffix_re)
intLit = ASTNumberLiteral(self.definition[pos:self.pos])
if hasSuffix:
return intLit
else:
return _udl(intLit)
string = self._parse_string()
if string is not None:
return ASTStringLiteral(string)
return _udl(ASTStringLiteral(string))
# character-literal
if self.match(char_literal_re):
prefix = self.last_match.group(1) # may be None when no prefix
data = self.last_match.group(2)
try:
return ASTCharLiteral(prefix, data)
charLit = ASTCharLiteral(prefix, data)
except UnicodeDecodeError as e:
self.fail("Can not handle character literal. Internal error was: %s" % e)
except UnsupportedMultiCharacterCharLiteral:
self.fail("Can not handle character literal"
" resulting in multiple decoded characters.")
# TODO: user-defined lit
return _udl(charLit)
return None
def _parse_fold_or_paren_expression(self) -> ASTExpression:
@ -5519,9 +5617,6 @@ class DefinitionParser(BaseParser):
refQual = '&'
exceptionSpec = None
override = None
final = None
initializer = None
self.skip_ws()
if self.skip_string('noexcept'):
if self.skip_string_and_ws('('):
@ -5532,6 +5627,13 @@ class DefinitionParser(BaseParser):
exceptionSpec = ASTNoexceptSpec(expr)
else:
exceptionSpec = ASTNoexceptSpec(None)
self.skip_ws()
if self.skip_string('->'):
trailingReturn = self._parse_type(named=False)
else:
trailingReturn = None
self.skip_ws()
override = self.skip_word_and_ws('override')
final = self.skip_word_and_ws('final')
@ -5540,6 +5642,7 @@ class DefinitionParser(BaseParser):
'override') # they can be permuted
self.skip_ws()
initializer = None
if self.skip_string('='):
self.skip_ws()
valid = ('0', 'delete', 'default')
@ -5553,8 +5656,8 @@ class DefinitionParser(BaseParser):
% '" or "'.join(valid))
return ASTParametersQualifiers(
args, volatile, const, refQual, exceptionSpec, override, final,
initializer)
args, volatile, const, refQual, exceptionSpec, trailingReturn,
override, final, initializer)
def _parse_decl_specs_simple(self, outer: str, typed: bool) -> ASTDeclSpecsSimple:
"""Just parse the simple ones."""

View File

@ -154,11 +154,11 @@ class AutosummaryRenderer:
def render(self, template_name: str, context: Dict) -> str:
"""Render a template file."""
if template_name.endswith('.rst'):
try:
template = self.env.get_template(template_name)
else:
# objtype is given as template_name
except TemplateNotFound:
try:
# objtype is given as template_name
template = self.env.get_template('autosummary/%s.rst' % template_name)
except TemplateNotFound:
# fallback to base.rst

View File

@ -26,7 +26,9 @@ _google_section_regex = re.compile(r'^(\s|\w)+:\s*$')
_google_typed_arg_regex = re.compile(r'\s*(.+?)\s*\(\s*(.*[^\s]+)\s*\)')
_numpy_section_regex = re.compile(r'^[=\-`:\'"~^_*+#<>]{2,}\s*$')
_single_colon_regex = re.compile(r'(?<!:):(?!:)')
_xref_regex = re.compile(r'(:(?:[a-zA-Z0-9]+[\-_+:.])*[a-zA-Z0-9]+:`.+?`)')
_xref_or_code_regex = re.compile(
r'((?::(?:[a-zA-Z0-9]+[\-_+:.])*[a-zA-Z0-9]+:`.+?`)|'
r'(?:``.+``))')
_bullet_list_regex = re.compile(r'^(\*|\+|\-)(\s+\S|\s*$)')
_enumerated_list_regex = re.compile(
r'^(?P<paren>\()?'
@ -724,7 +726,7 @@ class GoogleDocstring:
after_colon = []
colon = ''
found_colon = False
for i, source in enumerate(_xref_regex.split(line)):
for i, source in enumerate(_xref_or_code_regex.split(line)):
if found_colon:
after_colon.append(source)
else:

View File

@ -39,6 +39,16 @@ integer_literal_re = re.compile(r'[1-9][0-9]*')
octal_literal_re = re.compile(r'0[0-7]*')
hex_literal_re = re.compile(r'0[xX][0-9a-fA-F][0-9a-fA-F]*')
binary_literal_re = re.compile(r'0[bB][01][01]*')
integers_literal_suffix_re = re.compile(r'''(?x)
# unsigned and/or (long) long, in any order, but at least one of them
(
([uU] ([lL] | (ll) | (LL))?)
|
(([lL] | (ll) | (LL)) [uU]?)
)\b
# the ending word boundary is important for distinguishing
# between suffixes and UDLs in C++
''')
float_literal_re = re.compile(r'''(?x)
[+-]?(
# decimal
@ -51,6 +61,8 @@ float_literal_re = re.compile(r'''(?x)
| (0[xX][0-9a-fA-F]+\.([pP][+-]?[0-9a-fA-F]+)?)
)
''')
float_literal_suffix_re = re.compile(r'[fFlL]\b')
# the ending word boundary is important for distinguishing between suffixes and UDLs in C++
char_literal_re = re.compile(r'''(?x)
((?:u8)|u|U|L)?
'(
@ -67,7 +79,7 @@ char_literal_re = re.compile(r'''(?x)
def verify_description_mode(mode: str) -> None:
if mode not in ('lastIsName', 'noneIsName', 'markType', 'markName', 'param'):
if mode not in ('lastIsName', 'noneIsName', 'markType', 'markName', 'param', 'udl'):
raise Exception("Description mode '%s' is invalid." % mode)

View File

@ -125,13 +125,15 @@ def unwrap(obj: Any) -> Any:
return obj
def unwrap_all(obj: Any) -> Any:
def unwrap_all(obj: Any, *, stop: Callable = None) -> Any:
"""
Get an original object from wrapped object (unwrapping partials, wrapped
functions, and other decorators).
"""
while True:
if ispartial(obj):
if stop and stop(obj):
return obj
elif ispartial(obj):
obj = obj.func
elif inspect.isroutine(obj) and hasattr(obj, '__wrapped__'):
obj = obj.__wrapped__
@ -287,7 +289,8 @@ def isroutine(obj: Any) -> bool:
def iscoroutinefunction(obj: Any) -> bool:
"""Check if the object is coroutine-function."""
obj = unwrap_all(obj)
# unwrap staticmethod, classmethod and partial (except wrappers)
obj = unwrap_all(obj, stop=lambda o: hasattr(o, '__wrapped__'))
if hasattr(obj, '__code__') and inspect.iscoroutinefunction(obj):
# check obj.__code__ because iscoroutinefunction() crashes for custom method-like
# objects (see https://github.com/sphinx-doc/sphinx/issues/6605)

View File

@ -1,3 +1,7 @@
import asyncio
from functools import wraps
class AsyncClass:
async def do_coroutine(self):
"""A documented coroutine function"""
@ -16,3 +20,14 @@ class AsyncClass:
async def _other_coro_func():
return "run"
def myawait(f):
@wraps(f)
def wrapper(*args, **kwargs):
awaitable = f(*args, **kwargs)
return asyncio.run(awaitable)
return wrapper
sync_func = myawait(_other_coro_func)

View File

@ -1379,6 +1379,15 @@ def test_coroutine():
'',
]
# force-synchronized wrapper
actual = do_autodoc(app, 'function', 'target.coroutine.sync_func')
assert list(actual) == [
'',
'.. py:function:: sync_func()',
' :module: target.coroutine',
'',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_partialmethod(app):

View File

@ -145,37 +145,48 @@ def test_expressions():
exprCheck(expr, 'L' + expr + 'E')
expr = i + l + u
exprCheck(expr, 'L' + expr + 'E')
decimalFloats = ['5e42', '5e+42', '5e-42',
'5.', '5.e42', '5.e+42', '5.e-42',
'.5', '.5e42', '.5e+42', '.5e-42',
'5.0', '5.0e42', '5.0e+42', '5.0e-42']
hexFloats = ['ApF', 'Ap+F', 'Ap-F',
'A.', 'A.pF', 'A.p+F', 'A.p-F',
'.A', '.ApF', '.Ap+F', '.Ap-F',
'A.B', 'A.BpF', 'A.Bp+F', 'A.Bp-F']
for suffix in ['', 'f', 'F', 'l', 'L']:
for e in [
'5e42', '5e+42', '5e-42',
'5.', '5.e42', '5.e+42', '5.e-42',
'.5', '.5e42', '.5e+42', '.5e-42',
'5.0', '5.0e42', '5.0e+42', '5.0e-42']:
for e in decimalFloats:
expr = e + suffix
exprCheck(expr, 'L' + expr + 'E')
for e in [
'ApF', 'Ap+F', 'Ap-F',
'A.', 'A.pF', 'A.p+F', 'A.p-F',
'.A', '.ApF', '.Ap+F', '.Ap-F',
'A.B', 'A.BpF', 'A.Bp+F', 'A.Bp-F']:
for e in hexFloats:
expr = "0x" + e + suffix
exprCheck(expr, 'L' + expr + 'E')
exprCheck('"abc\\"cba"', 'LA8_KcE') # string
exprCheck('this', 'fpT')
# character literals
for p, t in [('', 'c'), ('u8', 'c'), ('u', 'Ds'), ('U', 'Di'), ('L', 'w')]:
exprCheck(p + "'a'", t + "97")
exprCheck(p + "'\\n'", t + "10")
exprCheck(p + "'\\012'", t + "10")
exprCheck(p + "'\\0'", t + "0")
exprCheck(p + "'\\x0a'", t + "10")
exprCheck(p + "'\\x0A'", t + "10")
exprCheck(p + "'\\u0a42'", t + "2626")
exprCheck(p + "'\\u0A42'", t + "2626")
exprCheck(p + "'\\U0001f34c'", t + "127820")
exprCheck(p + "'\\U0001F34C'", t + "127820")
charPrefixAndIds = [('', 'c'), ('u8', 'c'), ('u', 'Ds'), ('U', 'Di'), ('L', 'w')]
chars = [('a', '97'), ('\\n', '10'), ('\\012', '10'), ('\\0', '0'),
('\\x0a', '10'), ('\\x0A', '10'), ('\\u0a42', '2626'), ('\\u0A42', '2626'),
('\\U0001f34c', '127820'), ('\\U0001F34C', '127820')]
for p, t in charPrefixAndIds:
for c, val in chars:
exprCheck("{}'{}'".format(p, c), t + val)
# user-defined literals
for i in ints:
exprCheck(i + '_udl', 'clL_Zli4_udlEL' + i + 'EE')
exprCheck(i + 'uludl', 'clL_Zli5uludlEL' + i + 'EE')
for f in decimalFloats:
exprCheck(f + '_udl', 'clL_Zli4_udlEL' + f + 'EE')
exprCheck(f + 'fudl', 'clL_Zli4fudlEL' + f + 'EE')
for f in hexFloats:
exprCheck('0x' + f + '_udl', 'clL_Zli4_udlEL0x' + f + 'EE')
for p, t in charPrefixAndIds:
for c, val in chars:
exprCheck("{}'{}'_udl".format(p, c), 'clL_Zli4_udlE' + t + val + 'E')
exprCheck('"abc"_udl', 'clL_Zli4_udlELA3_KcEE')
# from issue #7294
exprCheck('6.62607015e-34q_J', 'clL_Zli3q_JEL6.62607015e-34EE')
# TODO: user-defined lit
# fold expressions, paren, name
exprCheck('(... + Ns)', '(... + Ns)', id4='flpl2Ns')
exprCheck('(Ns + ...)', '(Ns + ...)', id4='frpl2Ns')
exprCheck('(Ns + ... + 0)', '(Ns + ... + 0)', id4='fLpl2NsL0E')
@ -552,6 +563,21 @@ def test_function_definitions():
check('function', 'template<typename T> C()', {2: 'I0E1Cv'})
check('function', 'template<typename T> operator int()', {1: None, 2: 'I0Ecviv'})
# trailing return types
ids = {1: 'f', 2: '1fv'}
check('function', 'int f()', ids)
check('function', 'auto f() -> int', ids)
check('function', 'virtual auto f() -> int = 0', ids)
check('function', 'virtual auto f() -> int final', ids)
check('function', 'virtual auto f() -> int override', ids)
ids = {2: 'I0E1fv', 4: 'I0E1fiv'}
check('function', 'template<typename T> int f()', ids)
check('function', 'template<typename T> f() -> int', ids)
# from breathe#441
check('function', 'auto MakeThingy() -> Thingy*', {1: 'MakeThingy', 2: '10MakeThingyv'})
def test_operators():
check('function', 'void operator new()', {1: "new-operator", 2: "nwv"})

View File

@ -78,15 +78,17 @@ class InlineAttributeTest(BaseDocstringTest):
def test_class_data_member(self):
config = Config()
docstring = """data member description:
docstring = dedent("""\
data member description:
- a: b
"""
- a: b
""")
actual = str(GoogleDocstring(docstring, config=config, app=None,
what='attribute', name='some_data', obj=0))
expected = """data member description:
expected = dedent("""\
data member description:
- a: b"""
- a: b""")
self.assertEqual(expected, actual)
@ -95,10 +97,30 @@ class InlineAttributeTest(BaseDocstringTest):
docstring = """b: data member description with :ref:`reference`"""
actual = str(GoogleDocstring(docstring, config=config, app=None,
what='attribute', name='some_data', obj=0))
expected = """data member description with :ref:`reference`
expected = dedent("""\
data member description with :ref:`reference`
:type: b"""
:type: b""")
self.assertEqual(expected, actual)
def test_class_data_member_inline_no_type(self):
config = Config()
docstring = """data with ``a : in code`` and :ref:`reference` and no type"""
actual = str(GoogleDocstring(docstring, config=config, app=None,
what='attribute', name='some_data', obj=0))
expected = """data with ``a : in code`` and :ref:`reference` and no type"""
self.assertEqual(expected, actual)
def test_class_data_member_inline_ref_in_type(self):
config = Config()
docstring = """:class:`int`: data member description"""
actual = str(GoogleDocstring(docstring, config=config, app=None,
what='attribute', name='some_data', obj=0))
expected = dedent("""\
data member description
:type: :class:`int`""")
self.assertEqual(expected, actual)