From d2daa67b0079a69bee9be139bea1242e22427686 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 19 Nov 2021 12:33:41 -0800 Subject: [PATCH] ansible-test - Fix type hints. --- changelogs/fragments/ansible-test-fix-type-hints.yml | 2 ++ .../_internal/cli/commands/integration/network.py | 2 +- test/lib/ansible_test/_internal/cli/completers.py | 4 ++-- test/lib/ansible_test/_internal/cli/environments.py | 10 +++++----- .../_internal/commands/coverage/__init__.py | 4 ++-- .../ansible_test/_internal/commands/coverage/xml.py | 2 +- test/lib/ansible_test/_internal/containers.py | 2 +- test/lib/ansible_test/_internal/docker_util.py | 2 +- test/lib/ansible_test/_internal/provider/__init__.py | 2 +- test/lib/ansible_test/_internal/target.py | 2 +- 10 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 changelogs/fragments/ansible-test-fix-type-hints.yml diff --git a/changelogs/fragments/ansible-test-fix-type-hints.yml b/changelogs/fragments/ansible-test-fix-type-hints.yml new file mode 100644 index 00000000000..630504db368 --- /dev/null +++ b/changelogs/fragments/ansible-test-fix-type-hints.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - Fix type hints. diff --git a/test/lib/ansible_test/_internal/cli/commands/integration/network.py b/test/lib/ansible_test/_internal/cli/commands/integration/network.py index d070afda9b0..425a81520a9 100644 --- a/test/lib/ansible_test/_internal/cli/commands/integration/network.py +++ b/test/lib/ansible_test/_internal/cli/commands/integration/network.py @@ -60,7 +60,7 @@ def do_network_integration( add_environments(parser, completer, ControllerMode.DELEGATED, TargetMode.NETWORK_INTEGRATION) # network-integration -def complete_network_testcase(prefix, parsed_args, **_): # type: (str, argparse.Namespace, ...) -> t.List[str] +def complete_network_testcase(prefix: str, parsed_args: argparse.Namespace, **_) -> t.List[str]: """Return a list of test cases matching the given prefix if only one target was parsed from the command line, otherwise return an empty list.""" testcases = [] diff --git a/test/lib/ansible_test/_internal/cli/completers.py b/test/lib/ansible_test/_internal/cli/completers.py index a4b9c04f4ee..593ac8881af 100644 --- a/test/lib/ansible_test/_internal/cli/completers.py +++ b/test/lib/ansible_test/_internal/cli/completers.py @@ -13,14 +13,14 @@ from .argparsing.argcompletion import ( ) -def complete_target(completer, prefix, parsed_args, **_): # type: (OptionCompletionFinder, str, argparse.Namespace, ...) -> t.List[str] +def complete_target(completer: OptionCompletionFinder, prefix: str, parsed_args: argparse.Namespace, **_) -> t.List[str]: """Perform completion for the targets configured for the command being parsed.""" matches = find_target_completion(parsed_args.targets_func, prefix, completer.list_mode) completer.disable_completion_mangling = completer.list_mode and len(matches) > 1 return matches -def complete_choices(choices, prefix, **_): # type: (t.List[str], str, ...) -> t.List[str] +def complete_choices(choices: t.List[str], prefix: str, **_) -> t.List[str]: """Perform completion using the provided choices.""" matches = [choice for choice in choices if choice.startswith(prefix)] return matches diff --git a/test/lib/ansible_test/_internal/cli/environments.py b/test/lib/ansible_test/_internal/cli/environments.py index 640ff56bd41..964793f9002 100644 --- a/test/lib/ansible_test/_internal/cli/environments.py +++ b/test/lib/ansible_test/_internal/cli/environments.py @@ -526,24 +526,24 @@ def add_environment_remote( ) -def complete_remote_stage(prefix, **_): # type: (str, ...) -> t.List[str] +def complete_remote_stage(prefix: str, **_) -> t.List[str]: """Return a list of supported stages matching the given prefix.""" return [stage for stage in ('prod', 'dev') if stage.startswith(prefix)] -def complete_windows(prefix, parsed_args, **_): # type: (str, argparse.Namespace, ...) -> t.List[str] +def complete_windows(prefix: str, parsed_args: argparse.Namespace, **_) -> t.List[str]: """Return a list of supported Windows versions matching the given prefix, excluding versions already parsed from the command line.""" return [i for i in get_windows_version_choices() if i.startswith(prefix) and (not parsed_args.windows or i not in parsed_args.windows)] -def complete_network_platform(prefix, parsed_args, **_): # type: (str, argparse.Namespace, ...) -> t.List[str] +def complete_network_platform(prefix: str, parsed_args: argparse.Namespace, **_) -> t.List[str]: """Return a list of supported network platforms matching the given prefix, excluding platforms already parsed from the command line.""" images = sorted(filter_completion(NETWORK_COMPLETION)) return [i for i in images if i.startswith(prefix) and (not parsed_args.platform or i not in parsed_args.platform)] -def complete_network_platform_collection(prefix, parsed_args, **_): # type: (str, argparse.Namespace, ...) -> t.List[str] +def complete_network_platform_collection(prefix: str, parsed_args: argparse.Namespace, **_) -> t.List[str]: """Return a list of supported network platforms matching the given prefix, excluding collection platforms already parsed from the command line.""" left = prefix.split('=')[0] images = sorted(set(image.platform for image in filter_completion(NETWORK_COMPLETION).values())) @@ -551,7 +551,7 @@ def complete_network_platform_collection(prefix, parsed_args, **_): # type: (st return [i + '=' for i in images if i.startswith(left) and (not parsed_args.platform_collection or i not in [x[0] for x in parsed_args.platform_collection])] -def complete_network_platform_connection(prefix, parsed_args, **_): # type: (str, argparse.Namespace, ...) -> t.List[str] +def complete_network_platform_connection(prefix: str, parsed_args: argparse.Namespace, **_) -> t.List[str]: """Return a list of supported network platforms matching the given prefix, excluding connection platforms already parsed from the command line.""" left = prefix.split('=')[0] images = sorted(set(image.platform for image in filter_completion(NETWORK_COMPLETION).values())) diff --git a/test/lib/ansible_test/_internal/commands/coverage/__init__.py b/test/lib/ansible_test/_internal/commands/coverage/__init__.py index 50bc82632f8..47ad7bf8b72 100644 --- a/test/lib/ansible_test/_internal/commands/coverage/__init__.py +++ b/test/lib/ansible_test/_internal/commands/coverage/__init__.py @@ -152,7 +152,7 @@ def enumerate_python_arcs( modules, # type: t.Dict[str, str] collection_search_re, # type: t.Optional[t.Pattern] collection_sub_re, # type: t.Optional[t.Pattern] -): # type: (...) -> t.Generator[t.Tuple[str, t.Set[t.Tuple[int, int]]]] +): # type: (...) -> t.Generator[t.Tuple[str, t.Set[t.Tuple[int, int]]], None, None] """Enumerate Python code coverage arcs in the given file.""" if os.path.getsize(path) == 0: display.warning('Empty coverage file: %s' % path, verbosity=2) @@ -193,7 +193,7 @@ def enumerate_powershell_lines( path, # type: str collection_search_re, # type: t.Optional[t.Pattern] collection_sub_re, # type: t.Optional[t.Pattern] -): # type: (...) -> t.Generator[t.Tuple[str, t.Dict[int, int]]] +): # type: (...) -> t.Generator[t.Tuple[str, t.Dict[int, int]], None, None] """Enumerate PowerShell code coverage lines in the given file.""" if os.path.getsize(path) == 0: display.warning('Empty coverage file: %s' % path, verbosity=2) diff --git a/test/lib/ansible_test/_internal/commands/coverage/xml.py b/test/lib/ansible_test/_internal/commands/coverage/xml.py index ed9603c28fa..8a90f4a286a 100644 --- a/test/lib/ansible_test/_internal/commands/coverage/xml.py +++ b/test/lib/ansible_test/_internal/commands/coverage/xml.py @@ -131,7 +131,7 @@ def _generate_powershell_xml(coverage_file): # type: (str) -> Element return elem_coverage -def _add_cobertura_package(packages, package_name, package_data): # type: (SubElement, str, t.Dict[str, t.Dict[str, int]]) -> t.Tuple[int, int] +def _add_cobertura_package(packages, package_name, package_data): # type: (Element, str, t.Dict[str, t.Dict[str, int]]) -> t.Tuple[int, int] """Add a package element to the given packages element.""" elem_package = SubElement(packages, 'package') elem_classes = SubElement(elem_package, 'classes') diff --git a/test/lib/ansible_test/_internal/containers.py b/test/lib/ansible_test/_internal/containers.py index 8ce7b052e45..1157876bc6a 100644 --- a/test/lib/ansible_test/_internal/containers.py +++ b/test/lib/ansible_test/_internal/containers.py @@ -103,7 +103,7 @@ def run_support_container( args, # type: EnvironmentConfig context, # type: str image, # type: str - name, # type: name + name, # type: str ports, # type: t.List[int] aliases=None, # type: t.Optional[t.List[str]] start=True, # type: bool diff --git a/test/lib/ansible_test/_internal/docker_util.py b/test/lib/ansible_test/_internal/docker_util.py index a92ccbd1e83..6c6f403b3eb 100644 --- a/test/lib/ansible_test/_internal/docker_util.py +++ b/test/lib/ansible_test/_internal/docker_util.py @@ -254,7 +254,7 @@ def docker_run( raise ApplicationError('Failed to run docker image "%s".' % image) -def docker_start(args, container_id, options=None): # type: (EnvironmentConfig, str, t.Optional[t.List[str]]) -> (t.Optional[str], t.Optional[str]) +def docker_start(args, container_id, options=None): # type: (EnvironmentConfig, str, t.Optional[t.List[str]]) -> t.Tuple[t.Optional[str], t.Optional[str]] """ Start a docker container by name or ID """ diff --git a/test/lib/ansible_test/_internal/provider/__init__.py b/test/lib/ansible_test/_internal/provider/__init__.py index e8972ac87c4..78346142658 100644 --- a/test/lib/ansible_test/_internal/provider/__init__.py +++ b/test/lib/ansible_test/_internal/provider/__init__.py @@ -16,7 +16,7 @@ def get_path_provider_classes(provider_type): # type: (t.Type[TPathProvider]) - return sorted(get_subclasses(provider_type), key=lambda c: (c.priority, c.__name__)) -def find_path_provider(provider_type, # type: t.Type[TPathProvider], +def find_path_provider(provider_type, # type: t.Type[TPathProvider] provider_classes, # type: t.List[t.Type[TPathProvider]] path, # type: str walk, # type: bool diff --git a/test/lib/ansible_test/_internal/target.py b/test/lib/ansible_test/_internal/target.py index ced111f784f..879a7944ec6 100644 --- a/test/lib/ansible_test/_internal/target.py +++ b/test/lib/ansible_test/_internal/target.py @@ -155,7 +155,7 @@ def walk_units_targets(): # type: () -> t.Iterable[TestTarget] return walk_test_targets(path=data_context().content.unit_path, module_path=data_context().content.unit_module_path, extensions=('.py',), prefix='test_') -def walk_compile_targets(include_symlinks=True): # type: (bool) -> t.Iterable[TestTarget, ...] +def walk_compile_targets(include_symlinks=True): # type: (bool) -> t.Iterable[TestTarget] """Return an iterable of compile targets.""" return walk_test_targets(module_path=data_context().content.module_path, extensions=('.py',), extra_dirs=('bin',), include_symlinks=include_symlinks)