Type hint fixes.

pull/77226/head
Matt Clay 3 years ago
parent 3a3c496ade
commit 7c81a652c0

@ -19,6 +19,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import multiprocessing.synchronize
from multiprocessing import Lock
from ansible.module_utils.facts.system.pkg_mgr import PKG_MGRS
@ -27,7 +29,7 @@ if 'action_write_locks' not in globals():
# Do not initialize this more than once because it seems to bash
# the existing one. multiprocessing must be reloading the module
# when it forks?
action_write_locks = dict()
action_write_locks = dict() # type: dict[str | None, multiprocessing.synchronize.Lock]
# Below is a Lock for use when we weren't expecting a named module. It gets used when an action
# plugin invokes a module whose name does not match with the action's name. Slightly less

@ -29,6 +29,7 @@ import shlex
import zipfile
import re
import pkgutil
from ast import AST, Import, ImportFrom
from io import BytesIO

@ -56,10 +56,10 @@ if t.TYPE_CHECKING:
# files meta:
FileMetaKeysType,
]
ManifestValueType = dict[CollectionInfoKeysType, 'int | str | list[str] | dict[str, str] | None']
CollectionManifestType = dict[ManifestKeysType, ManifestValueType]
FileManifestEntryType = dict[FileMetaKeysType, 'str | int | None']
FilesManifestType = dict[t.Literal['files', 'format'], 'list[FileManifestEntryType] | int']
ManifestValueType = t.Dict[CollectionInfoKeysType, t.Union[int, str, t.List[str], t.Dict[str, str], None]]
CollectionManifestType = t.Dict[ManifestKeysType, ManifestValueType]
FileManifestEntryType = t.Dict[FileMetaKeysType, t.Union[str, int, None]]
FilesManifestType = t.Dict[t.Literal['files', 'format'], t.Union[t.List[FileManifestEntryType], int]]
import ansible.constants as C
from ansible.errors import AnsibleError

@ -108,6 +108,9 @@ class MultiGalaxyAPIProxy:
if isinstance(collection_candidate.src, GalaxyAPI)
else self._apis
)
last_err: t.Optional[Exception]
for api in api_lookup_order:
try:
version_metadata = api.get_collection_version_metadata(

@ -25,8 +25,7 @@ from ansible.parsing.yaml.constructor import AnsibleConstructor
from ansible.module_utils.common.yaml import HAS_LIBYAML, Parser
if HAS_LIBYAML:
class AnsibleLoader(Parser, AnsibleConstructor, Resolver):
class AnsibleLoader(Parser, AnsibleConstructor, Resolver): # type: ignore[misc] # pylint: disable=inconsistent-mro
def __init__(self, stream, file_name=None, vault_secrets=None):
Parser.__init__(self, stream) # pylint: disable=non-parent-init-called
AnsibleConstructor.__init__(self, file_name=file_name, vault_secrets=vault_secrets)
@ -37,7 +36,7 @@ else:
from yaml.scanner import Scanner
from yaml.parser import Parser
class AnsibleLoader(Reader, Scanner, Parser, Composer, AnsibleConstructor, Resolver):
class AnsibleLoader(Reader, Scanner, Parser, Composer, AnsibleConstructor, Resolver): # type: ignore[misc,no-redef] # pylint: disable=inconsistent-mro
def __init__(self, stream, file_name=None, vault_secrets=None):
Reader.__init__(self, stream)
Scanner.__init__(self)

@ -23,6 +23,9 @@ __metaclass__ = type
from abc import ABC
import types
import typing as t
from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_native
@ -31,10 +34,13 @@ from ansible.utils.display import Display
display = Display()
if t.TYPE_CHECKING:
from .loader import PluginPathContext
# Global so that all instances of a PluginLoader will share the caches
MODULE_CACHE = {}
PATH_CACHE = {}
PLUGIN_PATH_CACHE = {}
MODULE_CACHE = {} # type: dict[str, dict[str, types.ModuleType]]
PATH_CACHE = {} # type: dict[str, list[PluginPathContext] | None]
PLUGIN_PATH_CACHE = {} # type: dict[str, dict[str, dict[str, PluginPathContext]]]
def get_plugin_class(obj):

@ -223,8 +223,8 @@ class MyAddPolicy(object):
# keep connection objects on a per host basis to avoid repeated attempts to reconnect
SSH_CONNECTION_CACHE = {}
SFTP_CONNECTION_CACHE = {}
SSH_CONNECTION_CACHE = {} # type: dict[str, paramiko.client.SSHClient]
SFTP_CONNECTION_CACHE = {} # type: dict[str, paramiko.sftp_client.SFTPClient]
class Connection(ConnectionBase):

@ -87,6 +87,7 @@ host4 = {}
'''
import os
import typing as t
from functools import partial

@ -35,8 +35,8 @@ try:
from packaging.specifiers import SpecifierSet
from packaging.version import Version
except ImportError:
SpecifierSet = None
Version = None
SpecifierSet = None # type: ignore[misc]
Version = None # type: ignore[misc]
import importlib.util

Loading…
Cancel
Save