support pandas-style default spec by postprocessing tokens

This commit is contained in:
Keewis 2020-07-21 12:26:28 +02:00
parent 274d9fe4f9
commit 9b425606e7
2 changed files with 11 additions and 2 deletions

View File

@ -845,10 +845,17 @@ def _recombine_set_tokens(tokens: List[str]) -> List[str]:
def _tokenize_type_spec(spec: str) -> List[str]: def _tokenize_type_spec(spec: str) -> List[str]:
def postprocess(item):
if item.startswith("default"):
return [item[:7], item[7:]]
else:
return [item]
tokens = list( tokens = list(
item item
for item in _token_regex.split(spec) for raw_token in _token_regex.split(spec)
if item is not None and item.strip() for item in postprocess(raw_token)
if item
) )
return tokens return tokens

View File

@ -2013,6 +2013,7 @@ definition_after_normal_text : int
"int or float or None, optional", "int or float or None, optional",
'{"F", "C", "N"}', '{"F", "C", "N"}',
"{'F', 'C', 'N'}, default: 'F'", "{'F', 'C', 'N'}, default: 'F'",
"{'F', 'C', 'N or C'}, default 'F'",
'"ma{icious"', '"ma{icious"',
r"'with \'quotes\''", r"'with \'quotes\''",
) )
@ -2022,6 +2023,7 @@ definition_after_normal_text : int
["int", " or ", "float", " or ", "None", ", ", "optional"], ["int", " or ", "float", " or ", "None", ", ", "optional"],
["{", '"F"', ", ", '"C"', ", ", '"N"', "}"], ["{", '"F"', ", ", '"C"', ", ", '"N"', "}"],
["{", "'F'", ", ", "'C'", ", ", "'N'", "}", ", ", "default", ": ", "'F'"], ["{", "'F'", ", ", "'C'", ", ", "'N'", "}", ", ", "default", ": ", "'F'"],
["{", "'F'", ", ", "'C'", ", ", "'N or C'", "}", ", ", "default", " ", "'F'"],
['"ma{icious"'], ['"ma{icious"'],
[r"'with \'quotes\''"], [r"'with \'quotes\''"],
) )