[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,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]:

@ -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

Loading…
Cancel
Save