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'
modules = []
modules = [] # type: list[str] | None
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.'}

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

@ -308,7 +308,7 @@ class GalaxyAPI:
)
def __lt__(self, other_galaxy_api):
# type: (GalaxyAPI, GalaxyAPI) -> bool | NotImplemented
# type: (GalaxyAPI, GalaxyAPI) -> bool
"""Return whether the instance priority is higher than other."""
if not isinstance(other_galaxy_api, self.__class__):
return NotImplemented
@ -318,7 +318,7 @@ class GalaxyAPI:
self.name < self.name
)
@property
@property # type: ignore[misc] # https://github.com/python/mypy/issues/1362
@g_connect(['v1', 'v2', 'v3'])
def available_api_versions(self):
# 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.
"""
found_api = False
last_error = None
last_error = None # type: Exception | None
api_lookup_order = (
(requirement.src, )
@ -163,11 +163,11 @@ class MultiGalaxyAPIProxy:
)
def get_signatures(self, collection_candidate):
# type: (Candidate) -> list[dict[str, str]]
# type: (Candidate) -> list[str]
namespace = collection_candidate.namespace
name = collection_candidate.name
version = collection_candidate.ver
last_err = None
last_err = None # type: Exception | None
api_lookup_order = (
(collection_candidate.src, )

@ -524,10 +524,10 @@ class _ComputedReqKindsMixin:
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(

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

@ -29,7 +29,7 @@ try:
)
except ImportError:
"""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,
ItemsView,
KeysView,

@ -17,7 +17,7 @@ from ansible.utils.unsafe_proxy import wrap_var
class AnsibleJSONDecoder(json.JSONDecoder):
_vaults = {}
_vaults = {} # type: dict[str, VaultLib]
def __init__(self, *args, **kwargs):
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'))
# used to hold sudo/su stuff
DEPRECATED_ATTRIBUTES = []
DEPRECATED_ATTRIBUTES = [] # type: list[str]
def get_path(self):
''' return the absolute path of the playbook object and its line number '''

@ -46,7 +46,7 @@ class ActionBase(ABC):
'''
# 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):
self._task = task

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

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

@ -119,9 +119,9 @@ if HAS_TOML and hasattr(toml, 'TomlEncoder'):
AnsibleUnsafeBytes: 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:
def toml_dumps(data):
def toml_dumps(data): # type: (t.Any) -> str
return toml.dumps(convert_yaml_objects_to_native(data))

@ -24,7 +24,7 @@ _find_unsafe = re.compile(r'[\s\(\)\%\!^\"\<\>\&\|]').search
class ShellModule(PSShellModule):
# 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
SHELL_FAMILY = 'cmd'

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

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

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

@ -14,7 +14,7 @@ from xml.dom import minidom
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):
"""Base class for the result of a test case."""
output: str | None = None

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

@ -8,9 +8,9 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
try:
from collections.abc import Mapping # pylint: disable=ansible-bad-import-from
from collections.abc import Mapping
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

@ -18,7 +18,7 @@ display = Display()
class JsonRpcServer(object):
_objects = set()
_objects = set() # type: set[object]
def handle_request(self, request):
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
_HAS_CONTROLPERSIST = {}
_HAS_CONTROLPERSIST = {} # type: dict[str, bool]
def check_for_controlpersist(ssh_executable):

Loading…
Cancel
Save