add more delimiters so describing mappings becomes possible

This commit is contained in:
Keewis 2020-07-29 22:29:03 +02:00
parent 05bf00bd4c
commit e39c1a8d6a
2 changed files with 10 additions and 1 deletions

View File

@ -45,7 +45,8 @@ _enumerated_list_regex = re.compile(
r'(\d+|#|[ivxlcdm]+|[IVXLCDM]+|[a-zA-Z])'
r'(?(paren)\)|\.)(\s+\S|\s*$)')
_token_regex = re.compile(
r"(\sor\s|\sof\s|:\s|,\s|[{]|[}]"
r"(,\sor\s|\sor\s|\sof\s|:\s|\sto\s|,\sand\s|\sand\s|,\s"
r"|[{]|[}]"
r'|"(?:\\"|[^"])*"'
r"|'(?:\\'|[^'])*')"
)

View File

@ -2026,6 +2026,7 @@ definition_after_normal_text : int
def test_tokenize_type_spec(self):
specs = (
"str",
"int, float, or complex",
"int or float or None, optional",
'{"F", "C", "N"}',
"{'F', 'C', 'N'}, default: 'F'",
@ -2038,6 +2039,7 @@ definition_after_normal_text : int
tokens = (
["str"],
["int", ", ", "float", ", or ", "complex"],
["int", " or ", "float", " or ", "None", ", ", "optional"],
["{", '"F"', ", ", '"C"', ", ", '"N"', "}"],
["{", "'F'", ", ", "'C'", ", ", "'N'", "}", ", ", "default", ": ", "'F'"],
@ -2136,6 +2138,8 @@ definition_after_normal_text : int
a optional parameter with fixed values
param6 : int, default None
different default format
param7 : mapping of hashable to str, optional
a optional mapping
""")
expected = dedent("""\
:param param1: the data to work on
@ -2150,9 +2154,13 @@ definition_after_normal_text : int
:type param5: ``{"F", "C", "N"}``, *optional*
:param param6: different default format
:type param6: :class:`int`, *default* :obj:`None`
:param param7: a optional mapping
:type param7: :term:`mapping` of :term:`hashable` to :class:`str`, *optional*
""")
translations = {
"dict-like": ":term:`dict-like <mapping>`",
"mapping": ":term:`mapping`",
"hashable": ":term:`hashable`",
}
config = Config(
napoleon_use_param=True,