Skip to content

Conversation

@BenjyWiener
Copy link

Due to a mistake in one of the metavar_sep regexes, a closing bracket followed by '...' does not get the correct highlighting in the arguments help panel.

Minimum reproducible example:

from typing import Annotated

import typer


def main(args: Annotated[list[str] | None, typer.Argument()] = None): ...

typer.run(main)

Current --help output (note the closing bracket of [ARGS]... in the Arguments panel):

before

With this PR:

after

@svlandeg svlandeg added the bug Something isn't working label Jan 29, 2026
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the report, I'll have a look!

@svlandeg svlandeg self-assigned this Jan 29, 2026
@BenjyWiener
Copy link
Author

I was taking another look, and I'm wondering if there's a specific reason the opening and closing brackets are only matched at the beginning/end of the string. If not, it might make more sense to just remove the ^ and $, instead of specifically allowing a trailing ....

@BenjyWiener
Copy link
Author

The dots indicate that multiple arguments are accepted (hence the list annotation).

Comment on lines +108 to +109
@pytest.mark.parametrize("input_text", ["[ARGS]", "[ARGS]..."])
def test_metavar_highlighter(input_text: str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test succeeds on master with the normal [ARGS] but fails with [ARGS].... Succeeds with this PR.

Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the bug though it was hardly noticeable on my console 🥲

To write a regression test for this, I decided to move MetavarHighlighter to the module level, I think it's nicer anyway to define it together with the other highlighters. Then we can test for the highlighting directly, which works fine without the 3 dots but indeed fails as the regex doesn't consider the possibility of seeing 3 dots before the end of the string.

As @BenjyWiener mentioned, another option would be to remove the $. It just feels that these start and end markers are put in the regex on purpose, so I think the current solution is fine.

@svlandeg svlandeg removed their assignment Jan 30, 2026
highlights = [
r"^(?P<metavar_sep>(\[|<))",
r"(?P<metavar_sep>\|)",
r"(?P<metavar_sep>(\]|>))(\.\.\.)?$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiangolo: notice how this code was moved, but also changed to add the optional 3 dots at the end of the regex.

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 this pull request may close these issues.

2 participants