Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging
import re
from argparse import (ONE_OR_MORE, REMAINDER, SUPPRESS, ZERO_OR_MORE, Action, ArgumentParser,
_AppendAction, _AppendConstAction, _CountAction, _HelpAction,
_StoreConstAction, _VersionAction)
_ActionsContainer, _AppendAction, _AppendConstAction, _CountAction,
_HelpAction, _StoreConstAction, _VersionAction)
from collections import defaultdict
from contextlib import contextmanager
from functools import total_ordering
Expand All @@ -14,7 +14,7 @@
from textwrap import dedent
from typing import Any, Callable
from typing import Optional as Opt
from typing import Union
from typing import TypeVar, Union

try:
__version__ = version('shtab')
Expand All @@ -26,6 +26,7 @@

ShellType = str
CompleteType = dict[ShellType, Union[str, dict[ShellType, str]]]
_ActionsContainerT = TypeVar("_ActionsContainerT", bound=_ActionsContainer)
SUPPORTED_SHELLS: list[ShellType] = []
_SUPPORTED_COMPLETERS: dict[ShellType, Callable] = {}
CHOICE_FUNCTIONS: dict[str, CompleteType] = {
Expand Down Expand Up @@ -1508,12 +1509,12 @@ def __call__(self, parser, namespace, values, option_string=None):


def add_argument_to(
parser: ArgumentParser,
parser: _ActionsContainerT,
option_string: Union[str, list[str]] = "--print-completion",
help: str = "print shell completion script", # pylint: disable=W0622
parent: Opt[ArgumentParser] = None,
preamble: Union[str, dict[str, str]] = "",
):
) -> _ActionsContainerT:
"""
option_string:
iff positional (no `-` prefix) then `parser` is assumed to actually be
Expand Down
7 changes: 7 additions & 0 deletions tests/test_shtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,13 @@ def test_add_argument_to_optional(shell):
pytest.skip("WiP")


def test_add_argument_to_group_typing() -> None:
"""Ensure mypy accepts argument groups and the function preserves identity."""
parser = ArgumentParser(prog="test")
group = parser.add_argument_group("completion")
assert shtab.add_argument_to(group) is group


@fix_shell
def test_add_argument_to_positional(shell, capsys):
parser = ArgumentParser(prog="test")
Expand Down