More type hint fixes for module_utils. (#77198)

* Type hint fixes for module_utils.
* Fix type hints in module_utils.facts.
pull/77201/head
Matt Clay 3 years ago committed by GitHub
parent 86f00bd156
commit ccdb552d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,7 +31,7 @@ __metaclass__ = type
import re
try:
RE_FLAGS = re.VERBOSE | re.ASCII
RE_FLAGS = re.VERBOSE | re.ASCII # type: ignore[attr-defined]
except AttributeError:
RE_FLAGS = re.VERBOSE

@ -32,6 +32,8 @@ __metaclass__ = type
import fnmatch
import sys
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts import timeout
from ansible.module_utils.facts import collector
from ansible.module_utils.common.collections import is_string
@ -104,7 +106,7 @@ class CollectorMetaDataCollector(collector.BaseFactCollector):
'''Collector that provides a facts with the gather_subset metadata.'''
name = 'gather_subset'
_fact_ids = set([])
_fact_ids = set() # type: t.Set[str]
def __init__(self, collectors=None, namespace=None, gather_subset=None, module_setup=None):
super(CollectorMetaDataCollector, self).__init__(collectors, namespace)

@ -33,6 +33,8 @@ from collections import defaultdict
import platform
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts import timeout
@ -56,11 +58,11 @@ class CollectorNotFoundError(KeyError):
class BaseFactCollector:
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
_platform = 'Generic'
name = None # type: str | None
required_facts = set()
required_facts = set() # type: t.Set[str]
def __init__(self, collectors=None, namespace=None):
'''Base class for things that collect facts.

@ -29,6 +29,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
@ -50,7 +52,7 @@ class HardwareCollector(BaseFactCollector):
'processor_count',
# TODO: mounts isnt exactly hardware
'mounts',
'devices'])
'devices']) # type: t.Set[str]
_fact_class = Hardware
def collect(self, module=None, collected_facts=None):

@ -16,6 +16,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
@ -48,7 +50,7 @@ class NetworkCollector(BaseFactCollector):
'default_ipv4',
'default_ipv6',
'all_ipv4_addresses',
'all_ipv6_addresses'])
'all_ipv6_addresses']) # type: t.Set[str]
IPV6_SCOPE = {'0': 'global',
'10': 'host',

@ -21,13 +21,15 @@ __metaclass__ = type
import sys
import glob
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.utils import get_file_lines
from ansible.module_utils.facts.collector import BaseFactCollector
class FcWwnInitiatorFactCollector(BaseFactCollector):
name = 'fibre_channel_wwn'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
"""

@ -21,6 +21,8 @@ __metaclass__ = type
import sys
import subprocess
import ansible.module_utils.compat.typing as t
from ansible.module_utils.common.process import get_bin_path
from ansible.module_utils.facts.utils import get_file_content
from ansible.module_utils.facts.network.base import NetworkCollector
@ -28,7 +30,7 @@ from ansible.module_utils.facts.network.base import NetworkCollector
class IscsiInitiatorNetworkCollector(NetworkCollector):
name = 'iscsi'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
"""

@ -21,13 +21,15 @@ __metaclass__ = type
import sys
import subprocess
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.utils import get_file_content
from ansible.module_utils.facts.network.base import NetworkCollector
class NvmeInitiatorNetworkCollector(NetworkCollector):
name = 'nvme'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
"""

@ -18,6 +18,8 @@ __metaclass__ = type
import json
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.namespace import PrefixFactNamespace
from ansible.module_utils.facts.collector import BaseFactCollector
@ -25,7 +27,7 @@ from ansible.module_utils.facts.collector import BaseFactCollector
class FacterFactCollector(BaseFactCollector):
name = 'facter'
_fact_ids = set(['facter'])
_fact_ids = set(['facter']) # type: t.Set[str]
def __init__(self, collectors=None, namespace=None):
namespace = PrefixFactNamespace(namespace_name='facter',

@ -18,6 +18,8 @@ __metaclass__ = type
import json
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.namespace import PrefixFactNamespace
from ansible.module_utils.facts.collector import BaseFactCollector
@ -26,7 +28,7 @@ from ansible.module_utils.facts.collector import BaseFactCollector
class OhaiFactCollector(BaseFactCollector):
'''This is a subclass of Facts for including information gathered from Ohai.'''
name = 'ohai'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def __init__(self, collectors=None, namespace=None):
namespace = PrefixFactNamespace(namespace_name='ohai',

@ -20,12 +20,14 @@ __metaclass__ = type
import os
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
class ApparmorFactCollector(BaseFactCollector):
name = 'apparmor'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
facts_dict = {}

@ -18,6 +18,7 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ansible.module_utils.compat.typing as t
from ansible.module_utils._text import to_text
from ansible.module_utils.facts.collector import BaseFactCollector
@ -26,7 +27,7 @@ from ansible.module_utils.facts.collector import BaseFactCollector
class SystemCapabilitiesFactCollector(BaseFactCollector):
name = 'caps'
_fact_ids = set(['system_capabilities',
'system_capabilities_enforced'])
'system_capabilities_enforced']) # type: t.Set[str]
def collect(self, module=None, collected_facts=None):

@ -5,6 +5,8 @@ __metaclass__ = type
import os
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
@ -41,7 +43,7 @@ def is_chroot(module=None):
class ChrootFactCollector(BaseFactCollector):
name = 'chroot'
_fact_ids = set(['is_chroot'])
_fact_ids = set(['is_chroot']) # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
return {'is_chroot': is_chroot(module)}

@ -18,6 +18,8 @@ __metaclass__ = type
import shlex
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.utils import get_file_content
from ansible.module_utils.facts.collector import BaseFactCollector
@ -25,7 +27,7 @@ from ansible.module_utils.facts.collector import BaseFactCollector
class CmdLineFactCollector(BaseFactCollector):
name = 'cmdline'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def _get_proc_cmdline(self):
return get_file_content('/proc/cmdline')

@ -21,12 +21,14 @@ __metaclass__ = type
import datetime
import time
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
class DateTimeFactCollector(BaseFactCollector):
name = 'date_time'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
facts_dict = {}

@ -10,6 +10,8 @@ import os
import platform
import re
import ansible.module_utils.compat.typing as t
from ansible.module_utils.common.sys_info import get_distribution, get_distribution_version, \
get_distribution_codename
from ansible.module_utils.facts.utils import get_file_content
@ -684,7 +686,7 @@ class DistributionFactCollector(BaseFactCollector):
_fact_ids = set(['distribution_version',
'distribution_release',
'distribution_major_version',
'os_family'])
'os_family']) # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
collected_facts = collected_facts or {}

@ -16,6 +16,7 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.utils import get_file_content
@ -24,7 +25,7 @@ from ansible.module_utils.facts.collector import BaseFactCollector
class DnsFactCollector(BaseFactCollector):
name = 'dns'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
dns_facts = {}

@ -18,6 +18,8 @@ __metaclass__ = type
import os
import ansible.module_utils.compat.typing as t
from ansible.module_utils.six import iteritems
from ansible.module_utils.facts.collector import BaseFactCollector
@ -25,7 +27,7 @@ from ansible.module_utils.facts.collector import BaseFactCollector
class EnvFactCollector(BaseFactCollector):
name = 'env'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
env_facts = {}

@ -18,6 +18,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.utils import get_file_content
from ansible.module_utils.facts.collector import BaseFactCollector
@ -25,7 +27,7 @@ from ansible.module_utils.facts.collector import BaseFactCollector
class FipsFactCollector(BaseFactCollector):
name = 'fips'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
# NOTE: this is populated even if it is not set

@ -21,6 +21,8 @@ import json
import os
import stat
import ansible.module_utils.compat.typing as t
from ansible.module_utils._text import to_text
from ansible.module_utils.facts.utils import get_file_content
from ansible.module_utils.facts.collector import BaseFactCollector
@ -29,7 +31,7 @@ from ansible.module_utils.six.moves import configparser, StringIO
class LocalFactCollector(BaseFactCollector):
name = 'local'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
local_facts = {}

@ -20,13 +20,15 @@ __metaclass__ = type
import os
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.utils import get_file_lines
from ansible.module_utils.facts.collector import BaseFactCollector
class LSBFactCollector(BaseFactCollector):
name = 'lsb'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
STRIP_QUOTES = r'\'\"\\'
def _lsb_release_bin(self, lsb_path, module):

@ -8,6 +8,8 @@ __metaclass__ = type
import os
import subprocess
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
# A list of dicts. If there is a platform with more than one
@ -44,7 +46,7 @@ PKG_MGRS = [{'path': '/usr/bin/rpm-ostree', 'name': 'atomic_container'},
class OpenBSDPkgMgrFactCollector(BaseFactCollector):
name = 'pkg_mgr'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
_platform = 'OpenBSD'
def collect(self, module=None, collected_facts=None):
@ -57,7 +59,7 @@ class OpenBSDPkgMgrFactCollector(BaseFactCollector):
# the fact ends up being 'pkg_mgr' so stick with that naming/spelling
class PkgMgrFactCollector(BaseFactCollector):
name = 'pkg_mgr'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
_platform = 'Generic'
required_facts = set(['distribution'])

@ -20,6 +20,8 @@ import re
import socket
import platform
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.utils import get_file_content
from ansible.module_utils.facts.collector import BaseFactCollector
@ -37,7 +39,7 @@ class PlatformFactCollector(BaseFactCollector):
'machine',
'python_version',
'architecture',
'machine_id'])
'machine_id']) # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
platform_facts = {}

@ -18,6 +18,8 @@ __metaclass__ = type
import sys
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
try:
@ -32,7 +34,7 @@ except ImportError:
class PythonFactCollector(BaseFactCollector):
name = 'python'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
python_facts = {}

@ -18,6 +18,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
try:
@ -35,7 +37,7 @@ SELINUX_MODE_DICT = {
class SelinuxFactCollector(BaseFactCollector):
name = 'selinux'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
facts_dict = {}

@ -22,6 +22,8 @@ import os
import platform
import re
import ansible.module_utils.compat.typing as t
from ansible.module_utils._text import to_native
from ansible.module_utils.facts.utils import get_file_content
@ -37,7 +39,7 @@ if platform.system() != 'SunOS':
class ServiceMgrFactCollector(BaseFactCollector):
name = 'service_mgr'
_fact_ids = set()
_fact_ids = set() # type: t.Set[str]
required_facts = set(['platform', 'distribution'])
@staticmethod

@ -16,6 +16,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.utils import get_file_content
from ansible.module_utils.facts.collector import BaseFactCollector
@ -27,7 +29,7 @@ class SshPubKeyFactCollector(BaseFactCollector):
'ssh_host_key_dsa_public',
'ssh_host_key_rsa_public',
'ssh_host_key_ecdsa_public',
'ssh_host_key_ed25519_public'])
'ssh_host_key_ed25519_public']) # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
ssh_pub_key_facts = {}

@ -20,6 +20,8 @@ import getpass
import os
import pwd
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
@ -28,7 +30,7 @@ class UserFactCollector(BaseFactCollector):
_fact_ids = set(['user_id', 'user_uid', 'user_gid',
'user_gecos', 'user_dir', 'user_shell',
'real_user_id', 'effective_user_id',
'effective_group_ids'])
'effective_group_ids']) # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
user_facts = {}

@ -19,6 +19,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ansible.module_utils.compat.typing as t
from ansible.module_utils.facts.collector import BaseFactCollector
@ -63,7 +65,7 @@ class VirtualCollector(BaseFactCollector):
'virtualization_role',
'virtualization_tech_guest',
'virtualization_tech_host',
])
]) # type: t.Set[str]
def collect(self, module=None, collected_facts=None):
collected_facts = collected_facts or {}

@ -68,6 +68,7 @@ except ImportError:
# Python 3
import http.client as httplib # type: ignore[no-redef]
import ansible.module_utils.compat.typing as t
import ansible.module_utils.six.moves.http_cookiejar as cookiejar
import ansible.module_utils.six.moves.urllib.error as urllib_error
@ -86,7 +87,7 @@ except ImportError:
import urllib2 as urllib_request # type: ignore[no-redef]
from urllib2 import AbstractHTTPHandler, BaseHandler # type: ignore[no-redef]
urllib_request.HTTPRedirectHandler.http_error_308 = urllib_request.HTTPRedirectHandler.http_error_307
urllib_request.HTTPRedirectHandler.http_error_308 = urllib_request.HTTPRedirectHandler.http_error_307 # type: ignore[attr-defined]
try:
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlunparse, unquote
@ -160,7 +161,7 @@ if not HAS_SSLCONTEXT and HAS_SSL:
# The bundled backports.ssl_match_hostname should really be moved into its own file for processing
_BUNDLED_METADATA = {"pypi_name": "backports.ssl_match_hostname", "version": "3.7.0.1"}
LOADED_VERIFY_LOCATIONS = set()
LOADED_VERIFY_LOCATIONS = set() # type: t.Set[str]
HAS_MATCH_HOSTNAME = True
try:

Loading…
Cancel
Save