[stable-2.14] ansible-test - Add support for argcomplete 3 (#80482) (#80485)

(cherry picked from commit 0371ea08d6)
pull/80502/head
Matt Clay 2 years ago committed by GitHub
parent fb76b9e8a4
commit c4b33c7ce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- ansible-test - Add support for ``argcomplete`` version 3.

@ -17,6 +17,15 @@ class Substitute:
try: try:
import argcomplete import argcomplete
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 ( from argcomplete import (
CompletionFinder, CompletionFinder,
default_validator, default_validator,
@ -72,6 +81,12 @@ class CompType(enum.Enum):
def register_safe_action(action_type: t.Type[argparse.Action]) -> None: 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.""" """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: if argcomplete and action_type not in argcomplete.safe_actions:
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,) argcomplete.safe_actions += (action_type,)

@ -14,6 +14,9 @@ disable_error_code = misc
[mypy-argcomplete] [mypy-argcomplete]
ignore_missing_imports = True ignore_missing_imports = True
[mypy-argcomplete.finders]
ignore_missing_imports = True
[mypy-coverage] [mypy-coverage]
ignore_missing_imports = True ignore_missing_imports = True

Loading…
Cancel
Save