Fix ansible-test TypeVar type annotations.

This commit is contained in:
Matt Clay 2019-08-09 15:18:19 -07:00
parent 86ead40c2b
commit 3fac6a0adb
5 changed files with 44 additions and 28 deletions

View file

@ -16,6 +16,7 @@ from pylint.checkers.utils import check_messages
try:
from pylint.checkers.utils import parse_format_method_string
except ImportError:
# noinspection PyUnresolvedReferences
from pylint.checkers.strings import parse_format_method_string
_PY3K = sys.version_info[:2] >= (3, 0)

View file

@ -28,6 +28,11 @@ from .data import (
data_context,
)
try:
TIntegrationConfig = t.TypeVar('TIntegrationConfig', bound='IntegrationConfig')
except AttributeError:
TIntegrationConfig = None # pylint: disable=invalid-name
class EnvironmentConfig(CommonConfig):
"""Configuration common to all commands which execute in an environment."""

View file

@ -4,7 +4,6 @@ __metaclass__ = type
import json
import os
import collections
import datetime
import re
import time
@ -95,6 +94,7 @@ from .target import (
walk_posix_integration_targets,
walk_network_integration_targets,
walk_windows_integration_targets,
TIntegrationTarget,
)
from .changes import (
@ -118,6 +118,7 @@ from .config import (
PosixIntegrationConfig,
ShellConfig,
WindowsIntegrationConfig,
TIntegrationConfig,
)
from .metadata import (
@ -447,11 +448,8 @@ def command_network_integration(args):
instance.result.stop()
def network_init(args, internal_targets):
"""
:type args: NetworkIntegrationConfig
:type internal_targets: tuple[IntegrationTarget]
"""
def network_init(args, internal_targets): # type: (NetworkIntegrationConfig, t.Tuple[IntegrationTarget, ...]) -> None
"""Initialize platforms for network integration tests."""
if not args.platform:
return
@ -778,13 +776,11 @@ def windows_inventory(remotes):
return inventory
def command_integration_filter(args, targets, init_callback=None):
"""
:type args: IntegrationConfig
:type targets: collections.Iterable[IntegrationTarget]
:type init_callback: (IntegrationConfig, tuple[IntegrationTarget]) -> None
:rtype: tuple[IntegrationTarget]
"""
def command_integration_filter(args, # type: TIntegrationConfig
targets, # type: t.Iterable[TIntegrationTarget]
init_callback=None, # type: t.Callable[[TIntegrationConfig, t.Tuple[TIntegrationTarget, ...]], None]
): # type: (...) -> t.Tuple[TIntegrationTarget, ...]
"""Filter the given integration test targets."""
targets = tuple(target for target in targets if 'hidden/' not in target.aliases)
changes = get_changes_filter(args)

View file

@ -15,17 +15,21 @@ from ..util import (
try:
C = t.TypeVar('C', 'PathProvider', 'PathProvider')
TPathProvider = t.TypeVar('TPathProvider', bound='PathProvider')
except AttributeError:
pass
TPathProvider = None # pylint: disable=invalid-name
def get_path_provider_classes(provider_type): # type: (t.Type[C]) -> t.List[t.Type[C]]
def get_path_provider_classes(provider_type): # type: (t.Type[TPathProvider]) -> t.List[t.Type[TPathProvider]]
"""Return a list of path provider classes of the given type."""
return sorted(get_subclasses(provider_type), key=lambda c: (c.priority, c.__name__))
def find_path_provider(provider_type, provider_classes, path, walk): # type: (t.Type[C], t.List[t.Type[C]], str, bool) -> C
def find_path_provider(provider_type, # type: t.Type[TPathProvider],
provider_classes, # type: t.List[t.Type[TPathProvider]]
path, # type: str
walk, # type: bool
): # type: (...) -> TPathProvider
"""Return the first found path provider of the given type for the given path."""
sequences = sorted(set(pc.sequence for pc in provider_classes if pc.sequence > 0))

View file

@ -9,6 +9,8 @@ import errno
import itertools
import abc
from . import types as t
from .util import (
ApplicationError,
display,
@ -24,6 +26,16 @@ from .data import (
MODULE_EXTENSIONS = '.py', '.ps1'
try:
TCompletionTarget = t.TypeVar('TCompletionTarget', bound='CompletionTarget')
except AttributeError:
TCompletionTarget = None # pylint: disable=invalid-name
try:
TIntegrationTarget = t.TypeVar('TIntegrationTarget', bound='IntegrationTarget')
except AttributeError:
TIntegrationTarget = None # pylint: disable=invalid-name
def find_target_completion(target_func, prefix):
"""
@ -75,7 +87,7 @@ def walk_internal_targets(targets, includes=None, excludes=None, requires=None):
"""
targets = tuple(targets)
include_targets = sorted(filter_targets(targets, includes, errors=True, directories=False), key=lambda t: t.name)
include_targets = sorted(filter_targets(targets, includes, errors=True, directories=False), key=lambda target: target.name)
if requires:
require_targets = set(filter_targets(targets, requires, errors=True, directories=False))
@ -85,18 +97,16 @@ def walk_internal_targets(targets, includes=None, excludes=None, requires=None):
list(filter_targets(targets, excludes, errors=True, include=False, directories=False))
internal_targets = set(filter_targets(include_targets, excludes, errors=False, include=False, directories=False))
return tuple(sorted(internal_targets, key=lambda t: t.name))
return tuple(sorted(internal_targets, key=lambda target: target.name))
def filter_targets(targets, patterns, include=True, directories=True, errors=True):
"""
:type targets: collections.Iterable[CompletionTarget]
:type patterns: list[str]
:type include: bool
:type directories: bool
:type errors: bool
:rtype: collections.Iterable[CompletionTarget]
"""
def filter_targets(targets, # type: t.Iterable[TCompletionTarget]
patterns, # type: t.List[str]
include=True, # type: bool
directories=True, # type: bool
errors=True, # type: bool
): # type: (...) -> t.Iterable[TCompletionTarget]
"""Iterate over the given targets and filter them based on the supplied arguments."""
unmatched = set(patterns or ())
compiled_patterns = dict((p, re.compile('^%s$' % p)) for p in patterns) if patterns else None