Type hint fixes.

pull/77212/head
Matt Clay 3 years ago
parent e6f63be7a4
commit 0c4c18bc04

@ -61,7 +61,7 @@ class ConsoleCLI(CLI, cmd.Cmd):
''' '''
name = 'ansible-console' name = 'ansible-console'
modules = [] modules = [] # type: list[str] | None
ARGUMENTS = {'host-pattern': 'A name of a group in the inventory, a shell-like glob ' ARGUMENTS = {'host-pattern': 'A name of a group in the inventory, a shell-like glob '
'selecting hosts in inventory or any combination of the two separated by commas.'} 'selecting hosts in inventory or any combination of the two separated by commas.'}

@ -275,8 +275,8 @@ def _add_base_defs_deprecations(base_defs):
class ConfigManager(object): class ConfigManager(object):
DEPRECATED = [] DEPRECATED = [] # type: list[tuple[str, dict[str, str]]]
WARNINGS = set() WARNINGS = set() # type: set[str]
def __init__(self, conf_file=None, defs_file=None): def __init__(self, conf_file=None, defs_file=None):

@ -308,7 +308,7 @@ class GalaxyAPI:
) )
def __lt__(self, other_galaxy_api): def __lt__(self, other_galaxy_api):
# type: (GalaxyAPI, GalaxyAPI) -> bool | NotImplemented # type: (GalaxyAPI, GalaxyAPI) -> bool
"""Return whether the instance priority is higher than other.""" """Return whether the instance priority is higher than other."""
if not isinstance(other_galaxy_api, self.__class__): if not isinstance(other_galaxy_api, self.__class__):
return NotImplemented return NotImplemented
@ -318,7 +318,7 @@ class GalaxyAPI:
self.name < self.name self.name < self.name
) )
@property @property # type: ignore[misc] # https://github.com/python/mypy/issues/1362
@g_connect(['v1', 'v2', 'v3']) @g_connect(['v1', 'v2', 'v3'])
def available_api_versions(self): def available_api_versions(self):
# Calling g_connect will populate self._available_api_versions # Calling g_connect will populate self._available_api_versions

@ -42,7 +42,7 @@ class MultiGalaxyAPIProxy:
and reraise the last error if no valid API was found. and reraise the last error if no valid API was found.
""" """
found_api = False found_api = False
last_error = None last_error = None # type: Exception | None
api_lookup_order = ( api_lookup_order = (
(requirement.src, ) (requirement.src, )
@ -163,11 +163,11 @@ class MultiGalaxyAPIProxy:
) )
def get_signatures(self, collection_candidate): def get_signatures(self, collection_candidate):
# type: (Candidate) -> list[dict[str, str]] # type: (Candidate) -> list[str]
namespace = collection_candidate.namespace namespace = collection_candidate.namespace
name = collection_candidate.name name = collection_candidate.name
version = collection_candidate.ver version = collection_candidate.ver
last_err = None last_err = None # type: Exception | None
api_lookup_order = ( api_lookup_order = (
(collection_candidate.src, ) (collection_candidate.src, )

@ -524,10 +524,10 @@ class _ComputedReqKindsMixin:
return self._source_info return self._source_info
RequirementNamedTuple = namedtuple('Requirement', ('fqcn', 'ver', 'src', 'type', 'signature_sources')) RequirementNamedTuple = namedtuple('Requirement', ('fqcn', 'ver', 'src', 'type', 'signature_sources')) # type: ignore[name-match]
CandidateNamedTuple = namedtuple('Candidate', ('fqcn', 'ver', 'src', 'type', 'signatures')) CandidateNamedTuple = namedtuple('Candidate', ('fqcn', 'ver', 'src', 'type', 'signatures')) # type: ignore[name-match]
class Requirement( class Requirement(

@ -299,7 +299,7 @@ class CollectionDependencyProvider(AbstractProvider):
latest_matches = [] latest_matches = []
signatures = [] signatures = []
extra_signature_sources = [] extra_signature_sources = [] # type: list[str]
for version, src_server in coll_versions: for version, src_server in coll_versions:
tmp_candidate = Candidate(fqcn, version, src_server, 'galaxy', None) tmp_candidate = Candidate(fqcn, version, src_server, 'galaxy', None)

@ -29,7 +29,7 @@ try:
) )
except ImportError: except ImportError:
"""Use old lib location under 2.6-3.2.""" """Use old lib location under 2.6-3.2."""
from collections import ( # pylint: disable=deprecated-class from collections import ( # type: ignore[no-redef,attr-defined] # pylint: disable=deprecated-class
MappingView, MappingView,
ItemsView, ItemsView,
KeysView, KeysView,

@ -17,7 +17,7 @@ from ansible.utils.unsafe_proxy import wrap_var
class AnsibleJSONDecoder(json.JSONDecoder): class AnsibleJSONDecoder(json.JSONDecoder):
_vaults = {} _vaults = {} # type: dict[str, VaultLib]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs['object_hook'] = self.object_hook kwargs['object_hook'] = self.object_hook

@ -855,7 +855,7 @@ class Base(FieldAttributeBase):
_become_exe = FieldAttribute(isa='string', default=context.cliargs_deferred_get('become_exe')) _become_exe = FieldAttribute(isa='string', default=context.cliargs_deferred_get('become_exe'))
# used to hold sudo/su stuff # used to hold sudo/su stuff
DEPRECATED_ATTRIBUTES = [] DEPRECATED_ATTRIBUTES = [] # type: list[str]
def get_path(self): def get_path(self):
''' return the absolute path of the playbook object and its line number ''' ''' return the absolute path of the playbook object and its line number '''

@ -46,7 +46,7 @@ class ActionBase(ABC):
''' '''
# A set of valid arguments # A set of valid arguments
_VALID_ARGS = frozenset([]) _VALID_ARGS = frozenset([]) # type: frozenset[str]
def __init__(self, task, connection, play_context, loader, templar, shared_loader_obj): def __init__(self, task, connection, play_context, loader, templar, shared_loader_obj):
self._task = task self._task = task

@ -48,7 +48,7 @@ class ActionModule(ActionBase):
DEFAULT_SHUTDOWN_COMMAND_ARGS = '-r {delay_min} "{message}"' DEFAULT_SHUTDOWN_COMMAND_ARGS = '-r {delay_min} "{message}"'
DEFAULT_SUDOABLE = True DEFAULT_SUDOABLE = True
DEPRECATED_ARGS = {} DEPRECATED_ARGS = {} # type: dict[str, str]
BOOT_TIME_COMMANDS = { BOOT_TIME_COMMANDS = {
'freebsd': '/sbin/sysctl kern.boottime', 'freebsd': '/sbin/sysctl kern.boottime',

@ -26,8 +26,8 @@ class BecomeBase(AnsiblePlugin):
name = None # type: str | None name = None # type: str | None
# messages for detecting prompted password issues # messages for detecting prompted password issues
fail = tuple() fail = tuple() # type: tuple[str, ...]
missing = tuple() missing = tuple() # type: tuple[str, ...]
# many connection plugins cannot provide tty, set to True if your become # many connection plugins cannot provide tty, set to True if your become
# plugin requires a tty, i.e su # plugin requires a tty, i.e su

@ -119,9 +119,9 @@ if HAS_TOML and hasattr(toml, 'TomlEncoder'):
AnsibleUnsafeBytes: self.dump_funcs.get(str), AnsibleUnsafeBytes: self.dump_funcs.get(str),
AnsibleUnsafeText: self.dump_funcs.get(str), AnsibleUnsafeText: self.dump_funcs.get(str),
}) })
toml_dumps = partial(toml.dumps, encoder=AnsibleTomlEncoder()) toml_dumps = partial(toml.dumps, encoder=AnsibleTomlEncoder()) # type: t.Callable[[t.Any], str]
else: else:
def toml_dumps(data): def toml_dumps(data): # type: (t.Any) -> str
return toml.dumps(convert_yaml_objects_to_native(data)) return toml.dumps(convert_yaml_objects_to_native(data))

@ -24,7 +24,7 @@ _find_unsafe = re.compile(r'[\s\(\)\%\!^\"\<\>\&\|]').search
class ShellModule(PSShellModule): class ShellModule(PSShellModule):
# Common shell filenames that this plugin handles # Common shell filenames that this plugin handles
COMPATIBLE_SHELLS = frozenset() COMPATIBLE_SHELLS = frozenset() # type: frozenset[str]
# Family of shells this has. Must match the filename without extension # Family of shells this has. Must match the filename without extension
SHELL_FAMILY = 'cmd' SHELL_FAMILY = 'cmd'

@ -62,7 +62,7 @@ class ShellModule(ShellBase):
# Common shell filenames that this plugin handles # Common shell filenames that this plugin handles
# Powershell is handled differently. It's selected when winrm is the # Powershell is handled differently. It's selected when winrm is the
# connection # connection
COMPATIBLE_SHELLS = frozenset() COMPATIBLE_SHELLS = frozenset() # type: frozenset[str]
# Family of shells this has. Must match the filename without extension # Family of shells this has. Must match the filename without extension
SHELL_FAMILY = 'powershell' SHELL_FAMILY = 'powershell'

@ -40,10 +40,10 @@ class TerminalBase(ABC):
''' '''
#: compiled bytes regular expressions as stdout #: compiled bytes regular expressions as stdout
terminal_stdout_re = [] terminal_stdout_re = [] # type: list[re.Pattern]
#: compiled bytes regular expressions as stderr #: compiled bytes regular expressions as stderr
terminal_stderr_re = [] terminal_stderr_re = [] # type: list[re.Pattern]
#: compiled bytes regular expressions to remove ANSI codes #: compiled bytes regular expressions to remove ANSI codes
ansi_re = [ ansi_re = [

@ -61,7 +61,7 @@ from ansible.inventory.host import Host
from ansible.inventory.group import Group from ansible.inventory.group import Group
from ansible.utils.vars import combine_vars from ansible.utils.vars import combine_vars
FOUND = {} FOUND = {} # type: dict[str, list[str]]
class VarsModule(BaseVarsPlugin): class VarsModule(BaseVarsPlugin):

@ -14,7 +14,7 @@ from xml.dom import minidom
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
@dataclasses.dataclass @dataclasses.dataclass # type: ignore[misc] # https://github.com/python/mypy/issues/5374
class TestResult(metaclass=abc.ABCMeta): class TestResult(metaclass=abc.ABCMeta):
"""Base class for the result of a test case.""" """Base class for the result of a test case."""
output: str | None = None output: str | None = None

@ -660,7 +660,7 @@ class _AnsibleCollectionPkgLoader(_AnsibleCollectionPkgLoaderBase):
# loads everything under a collection, including handling redirections defined by the collection # loads everything under a collection, including handling redirections defined by the collection
class _AnsibleCollectionLoader(_AnsibleCollectionPkgLoaderBase): class _AnsibleCollectionLoader(_AnsibleCollectionPkgLoaderBase):
# HACK: stash this in a better place # HACK: stash this in a better place
_redirected_package_map = {} _redirected_package_map = {} # type: dict[str, str]
_allows_package_code = True _allows_package_code = True
def _validate_args(self): def _validate_args(self):

@ -8,9 +8,9 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
try: try:
from collections.abc import Mapping # pylint: disable=ansible-bad-import-from from collections.abc import Mapping
except ImportError: except ImportError:
from collections import Mapping # pylint: disable=ansible-bad-import-from from collections import Mapping # type: ignore[no-redef,attr-defined] # pylint: disable=ansible-bad-import-from
from ansible.module_utils.common.yaml import yaml_load from ansible.module_utils.common.yaml import yaml_load

@ -18,7 +18,7 @@ display = Display()
class JsonRpcServer(object): class JsonRpcServer(object):
_objects = set() _objects = set() # type: set[object]
def handle_request(self, request): def handle_request(self, request):
request = json.loads(to_text(request, errors='surrogate_then_replace')) request = json.loads(to_text(request, errors='surrogate_then_replace'))

@ -27,7 +27,7 @@ from ansible.module_utils._text import to_bytes
from ansible.module_utils.compat.paramiko import paramiko from ansible.module_utils.compat.paramiko import paramiko
_HAS_CONTROLPERSIST = {} _HAS_CONTROLPERSIST = {} # type: dict[str, bool]
def check_for_controlpersist(ssh_executable): def check_for_controlpersist(ssh_executable):

Loading…
Cancel
Save