Fix ansible-test TypeVar type annotations.
This commit is contained in:
parent
86ead40c2b
commit
3fac6a0adb
5 changed files with 44 additions and 28 deletions
|
@ -16,6 +16,7 @@ from pylint.checkers.utils import check_messages
|
||||||
try:
|
try:
|
||||||
from pylint.checkers.utils import parse_format_method_string
|
from pylint.checkers.utils import parse_format_method_string
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
from pylint.checkers.strings import parse_format_method_string
|
from pylint.checkers.strings import parse_format_method_string
|
||||||
|
|
||||||
_PY3K = sys.version_info[:2] >= (3, 0)
|
_PY3K = sys.version_info[:2] >= (3, 0)
|
||||||
|
|
|
@ -28,6 +28,11 @@ from .data import (
|
||||||
data_context,
|
data_context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
TIntegrationConfig = t.TypeVar('TIntegrationConfig', bound='IntegrationConfig')
|
||||||
|
except AttributeError:
|
||||||
|
TIntegrationConfig = None # pylint: disable=invalid-name
|
||||||
|
|
||||||
|
|
||||||
class EnvironmentConfig(CommonConfig):
|
class EnvironmentConfig(CommonConfig):
|
||||||
"""Configuration common to all commands which execute in an environment."""
|
"""Configuration common to all commands which execute in an environment."""
|
||||||
|
|
|
@ -4,7 +4,6 @@ __metaclass__ = type
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import collections
|
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
@ -95,6 +94,7 @@ from .target import (
|
||||||
walk_posix_integration_targets,
|
walk_posix_integration_targets,
|
||||||
walk_network_integration_targets,
|
walk_network_integration_targets,
|
||||||
walk_windows_integration_targets,
|
walk_windows_integration_targets,
|
||||||
|
TIntegrationTarget,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .changes import (
|
from .changes import (
|
||||||
|
@ -118,6 +118,7 @@ from .config import (
|
||||||
PosixIntegrationConfig,
|
PosixIntegrationConfig,
|
||||||
ShellConfig,
|
ShellConfig,
|
||||||
WindowsIntegrationConfig,
|
WindowsIntegrationConfig,
|
||||||
|
TIntegrationConfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .metadata import (
|
from .metadata import (
|
||||||
|
@ -447,11 +448,8 @@ def command_network_integration(args):
|
||||||
instance.result.stop()
|
instance.result.stop()
|
||||||
|
|
||||||
|
|
||||||
def network_init(args, internal_targets):
|
def network_init(args, internal_targets): # type: (NetworkIntegrationConfig, t.Tuple[IntegrationTarget, ...]) -> None
|
||||||
"""
|
"""Initialize platforms for network integration tests."""
|
||||||
:type args: NetworkIntegrationConfig
|
|
||||||
:type internal_targets: tuple[IntegrationTarget]
|
|
||||||
"""
|
|
||||||
if not args.platform:
|
if not args.platform:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -778,13 +776,11 @@ def windows_inventory(remotes):
|
||||||
return inventory
|
return inventory
|
||||||
|
|
||||||
|
|
||||||
def command_integration_filter(args, targets, init_callback=None):
|
def command_integration_filter(args, # type: TIntegrationConfig
|
||||||
"""
|
targets, # type: t.Iterable[TIntegrationTarget]
|
||||||
:type args: IntegrationConfig
|
init_callback=None, # type: t.Callable[[TIntegrationConfig, t.Tuple[TIntegrationTarget, ...]], None]
|
||||||
:type targets: collections.Iterable[IntegrationTarget]
|
): # type: (...) -> t.Tuple[TIntegrationTarget, ...]
|
||||||
:type init_callback: (IntegrationConfig, tuple[IntegrationTarget]) -> None
|
"""Filter the given integration test targets."""
|
||||||
:rtype: tuple[IntegrationTarget]
|
|
||||||
"""
|
|
||||||
targets = tuple(target for target in targets if 'hidden/' not in target.aliases)
|
targets = tuple(target for target in targets if 'hidden/' not in target.aliases)
|
||||||
changes = get_changes_filter(args)
|
changes = get_changes_filter(args)
|
||||||
|
|
||||||
|
|
|
@ -15,17 +15,21 @@ from ..util import (
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
C = t.TypeVar('C', 'PathProvider', 'PathProvider')
|
TPathProvider = t.TypeVar('TPathProvider', bound='PathProvider')
|
||||||
except AttributeError:
|
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 a list of path provider classes of the given type."""
|
||||||
return sorted(get_subclasses(provider_type), key=lambda c: (c.priority, c.__name__))
|
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."""
|
"""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))
|
sequences = sorted(set(pc.sequence for pc in provider_classes if pc.sequence > 0))
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ import errno
|
||||||
import itertools
|
import itertools
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
|
from . import types as t
|
||||||
|
|
||||||
from .util import (
|
from .util import (
|
||||||
ApplicationError,
|
ApplicationError,
|
||||||
display,
|
display,
|
||||||
|
@ -24,6 +26,16 @@ from .data import (
|
||||||
|
|
||||||
MODULE_EXTENSIONS = '.py', '.ps1'
|
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):
|
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)
|
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:
|
if requires:
|
||||||
require_targets = set(filter_targets(targets, requires, errors=True, directories=False))
|
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))
|
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))
|
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):
|
def filter_targets(targets, # type: t.Iterable[TCompletionTarget]
|
||||||
"""
|
patterns, # type: t.List[str]
|
||||||
:type targets: collections.Iterable[CompletionTarget]
|
include=True, # type: bool
|
||||||
:type patterns: list[str]
|
directories=True, # type: bool
|
||||||
:type include: bool
|
errors=True, # type: bool
|
||||||
:type directories: bool
|
): # type: (...) -> t.Iterable[TCompletionTarget]
|
||||||
:type errors: bool
|
"""Iterate over the given targets and filter them based on the supplied arguments."""
|
||||||
:rtype: collections.Iterable[CompletionTarget]
|
|
||||||
"""
|
|
||||||
unmatched = set(patterns or ())
|
unmatched = set(patterns or ())
|
||||||
compiled_patterns = dict((p, re.compile('^%s$' % p)) for p in patterns) if patterns else None
|
compiled_patterns = dict((p, re.compile('^%s$' % p)) for p in patterns) if patterns else None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue