dadadel / pyment

Format and convert Python docstrings and generates patches
GNU General Public License v3.0
905 stars 62 forks source link

Crash on nested square brackets in type annotation #120

Open tmke8 opened 2 years ago

tmke8 commented 2 years ago

pyment crashes on this function:

def map_over_results_index(
    results: Results,
    mapper: Callable[[Tuple[str, str, str, str, str]], Tuple[str, str, str, str, str]],
) -> Results:
    """Change the values of the index with a transformation function."""

though I'm pretty sure that this is valid (type checkers like mypy don't complain).

Traceback (most recent call last):
  File "[...]/bin/pyment", line 8, in <module>
    sys.exit(main())
  File "[...]/lib/python3.9/site-packages/pyment/pymentapp.py", line 171, in main
    run(source, files, args.input, args.output,
  File "[...]/lib/python3.9/site-packages/pyment/pymentapp.py", line 105, in run
    c.proceed()
  File "[...]/lib/python3.9/site-packages/pyment/pyment.py", line 378, in proceed
    self._parse()
  File "[...]/lib/python3.9/site-packages/pyment/pyment.py", line 132, in _parse
    e = DocString(elem.replace('\n', ' '), spaces, quotes=self.quotes,
  File "[...]/lib/python3.9/site-packages/pyment/docstring.py", line 1377, in __init__
    self.parse_definition()
  File "[...]/lib/python3.9/site-packages/pyment/docstring.py", line 1490, in parse_definition
    extracted = self._extract_signature_elements(self._remove_signature_comment(l))
  File "[...]/lib/python3.9/site-packages/pyment/docstring.py", line 1547, in _extract_signature_elements
    raise Exception("unexpected nested element after "+str(inside)+" while reading "+reading)
Exception: unexpected nested element after [ while reading param