Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when defining multiple highlight regexes with the same style #36

Closed
hamdanal opened this issue Nov 5, 2022 · 0 comments · Fixed by #37
Closed

Crash when defining multiple highlight regexes with the same style #36

hamdanal opened this issue Nov 5, 2022 · 0 comments · Fixed by #37
Labels
bug Something isn't working

Comments

@hamdanal
Copy link
Owner

hamdanal commented Nov 5, 2022

Since version 0.4.0
$ cat t.py

import argparse
from rich_argparse import RichHelpFormatter
RichHelpFormatter.highlights.append(r"'(?P<syntax>[^']*)'")
parser = argparse.ArgumentParser(formatter_class=RichHelpFormatter)
parser.print_help()

$python -m t

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/t/t.py", line 7, in <module>
    parser.print_help()
  File "/usr/lib/python3.10/argparse.py", line 2568, in print_help
    self._print_message(self.format_help(), file)
  File "/usr/lib/python3.10/argparse.py", line 2545, in format_help
    formatter.add_arguments(action_group._group_actions)
  File "/usr/lib/python3.10/argparse.py", line 289, in add_arguments
    self.add_argument(action)
  File "/tmp/t/venv/lib/python3.10/site-packages/rich_argparse.py", line 135, in add_argument
    self._current_section.rich_actions.extend(self._rich_format_action(action))
  File "/tmp/t/venv/lib/python3.10/site-packages/rich_argparse.py", line 239, in _rich_format_action
    help = self._rich_expand_help(action) if action.help and action.help.strip() else None
  File "/tmp/t/venv/lib/python3.10/site-packages/rich_argparse.py", line 221, in _rich_expand_help
    rich_help.highlight_regex("|".join(self.highlights), style_prefix="argparse.")
  File "/tmp/t/venv/lib/python3.10/site-packages/rich/text.py", line 579, in highlight_regex
    for match in re.finditer(re_highlight, plain):
  File "/usr/lib/python3.10/re.py", line 247, in finditer
    return _compile(pattern, flags).finditer(string)
  File "/usr/lib/python3.10/re.py", line 303, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.10/sre_compile.py", line 788, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.10/sre_parse.py", line 955, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib/python3.10/sre_parse.py", line 444, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.10/sre_parse.py", line 838, in _parse
    raise source.error(err.msg, len(name) + 1) from None
re.error: redefinition of group name 'syntax' as group 3; was group 2 at position 61
@hamdanal hamdanal added the bug Something isn't working label Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant