diff options
3 files changed, 25 insertions, 5 deletions
diff --git a/changelogs/fragments/ansible-test-argcomplete-3.yml b/changelogs/fragments/ansible-test-argcomplete-3.yml new file mode 100644 index 0000000000..0c0b01b5d0 --- /dev/null +++ b/changelogs/fragments/ansible-test-argcomplete-3.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - Add support for ``argcomplete`` version 3. diff --git a/test/lib/ansible_test/_internal/cli/argparsing/argcompletion.py b/test/lib/ansible_test/_internal/cli/argparsing/argcompletion.py index 219c33f4ff..26abcf82fd 100644 --- a/test/lib/ansible_test/_internal/cli/argparsing/argcompletion.py +++ b/test/lib/ansible_test/_internal/cli/argparsing/argcompletion.py @@ -17,10 +17,19 @@ class Substitute: try: import argcomplete - from argcomplete import ( - CompletionFinder, - default_validator, - ) + try: + # argcomplete 3+ + # see: https://github.com/kislyuk/argcomplete/commit/bd781cb08512b94966312377186ebc5550f46ae0 + from argcomplete.finders import ( + CompletionFinder, + default_validator, + ) + except ImportError: + # argcomplete <3 + from argcomplete import ( + CompletionFinder, + default_validator, + ) warn = argcomplete.warn # pylint: disable=invalid-name except ImportError: @@ -72,7 +81,13 @@ class CompType(enum.Enum): def register_safe_action(action_type: t.Type[argparse.Action]) -> None: """Register the given action as a safe action for argcomplete to use during completion if it is not already registered.""" if argcomplete and action_type not in argcomplete.safe_actions: - argcomplete.safe_actions += (action_type,) + if isinstance(argcomplete.safe_actions, set): + # argcomplete 3+ + # see: https://github.com/kislyuk/argcomplete/commit/bd781cb08512b94966312377186ebc5550f46ae0 + argcomplete.safe_actions.add(action_type) + else: + # argcomplete <3 + argcomplete.safe_actions += (action_type,) def get_comp_type() -> t.Optional[CompType]: diff --git a/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-test.ini b/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-test.ini index 190e9529a0..55738f87c6 100644 --- a/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-test.ini +++ b/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-test.ini @@ -14,6 +14,9 @@ disable_error_code = misc [mypy-argcomplete] ignore_missing_imports = True +[mypy-argcomplete.finders] +ignore_missing_imports = True + [mypy-coverage] ignore_missing_imports = True |