Additional type hinting cleanup. (#77188)

pull/77191/head
Matt Clay 3 years ago committed by GitHub
parent 74a204e6f1
commit 5a1b891917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,7 +16,7 @@ from functools import partial as _partial
try: try:
import typing as t import typing as t
except ImportError: except ImportError:
t = None # type: types.ModuleType | None t = None # type: types.ModuleType | None # type: ignore[no-redef]
HAS_LIBYAML = False HAS_LIBYAML = False
try: try:
@ -38,9 +38,9 @@ else:
Parser = _yaml.cyaml.CParser Parser = _yaml.cyaml.CParser
HAS_LIBYAML = True HAS_LIBYAML = True
except AttributeError: except AttributeError:
SafeLoader = _yaml.SafeLoader # type: t.Type[_yaml.CSafeLoader] | t.Type[_yaml.SafeLoader] SafeLoader = _yaml.SafeLoader # type: t.Type[_yaml.CSafeLoader] | t.Type[_yaml.SafeLoader] # type: ignore[no-redef]
SafeDumper = _yaml.SafeDumper # type: t.Type[_yaml.CSafeDumper] | t.Type[_yaml.SafeDumper] SafeDumper = _yaml.SafeDumper # type: t.Type[_yaml.CSafeDumper] | t.Type[_yaml.SafeDumper] # type: ignore[no-redef]
Parser = _yaml.parser.Parser # type: t.Type[_yaml.cyaml.CParser] | t.Type[_yaml.parser.Parser] Parser = _yaml.parser.Parser # type: t.Type[_yaml.cyaml.CParser] | t.Type[_yaml.parser.Parser] # type: ignore[no-redef]
yaml_load = _partial(_yaml.load, Loader=SafeLoader) yaml_load = _partial(_yaml.load, Loader=SafeLoader)
yaml_load_all = _partial(_yaml.load_all, Loader=SafeLoader) yaml_load_all = _partial(_yaml.load_all, Loader=SafeLoader)

@ -5,13 +5,15 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
import types
PARAMIKO_IMPORT_ERR = None PARAMIKO_IMPORT_ERR = None
paramiko = None
try: try:
import paramiko import paramiko
# paramiko and gssapi are incompatible and raise AttributeError not ImportError # paramiko and gssapi are incompatible and raise AttributeError not ImportError
# When running in FIPS mode, cryptography raises InternalError # When running in FIPS mode, cryptography raises InternalError
# https://bugzilla.redhat.com/show_bug.cgi?id=1778939 # https://bugzilla.redhat.com/show_bug.cgi?id=1778939
except Exception as err: except Exception as err:
paramiko = None # type: types.ModuleType | None # type: ignore[no-redef]
PARAMIKO_IMPORT_ERR = err PARAMIKO_IMPORT_ERR = err

@ -45,13 +45,13 @@ try:
except ImportError: except ImportError:
try: try:
# backport package installed in the system # backport package installed in the system
import selectors2 as _system_selectors import selectors2 as _system_selectors # type: ignore[no-redef]
except ImportError: except ImportError:
_system_selectors = None # type: types.ModuleType | None _system_selectors = None # type: types.ModuleType | None # type: ignore[no-redef]
if _system_selectors: if _system_selectors:
selectors = _system_selectors selectors = _system_selectors
else: else:
# Our bundled copy # Our bundled copy
from ansible.module_utils.compat import _selectors2 as selectors from ansible.module_utils.compat import _selectors2 as selectors # type: ignore[no-redef]
sys.modules['ansible.module_utils.compat.selectors'] = selectors sys.modules['ansible.module_utils.compat.selectors'] = selectors

@ -33,7 +33,7 @@ import types
try: try:
import typing as t import typing as t
except ImportError: except ImportError:
t = None # type: types.ModuleType | None t = None # type: types.ModuleType | None # type: ignore[no-redef]
from ansible.module_utils.facts.collector import BaseFactCollector from ansible.module_utils.facts.collector import BaseFactCollector

@ -66,10 +66,9 @@ try:
import httplib import httplib
except ImportError: except ImportError:
# Python 3 # Python 3
import http.client as httplib import http.client as httplib # type: ignore[no-redef]
import ansible.module_utils.six.moves.http_cookiejar as cookiejar import ansible.module_utils.six.moves.http_cookiejar as cookiejar
import ansible.module_utils.six.moves.urllib.request as urllib_request
import ansible.module_utils.six.moves.urllib.error as urllib_error import ansible.module_utils.six.moves.urllib.error as urllib_error
from ansible.module_utils.common.collections import Mapping from ansible.module_utils.common.collections import Mapping
@ -84,8 +83,8 @@ try:
from urllib.request import AbstractHTTPHandler, BaseHandler from urllib.request import AbstractHTTPHandler, BaseHandler
except ImportError: except ImportError:
# python2 # python2
import urllib2 as urllib_request import urllib2 as urllib_request # type: ignore[no-redef]
from urllib2 import AbstractHTTPHandler, BaseHandler 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
@ -269,7 +268,7 @@ try:
except ImportError: except ImportError:
GSSAPI_IMP_ERR = traceback.format_exc() GSSAPI_IMP_ERR = traceback.format_exc()
HTTPGSSAPIAuthHandler = None # type: types.ModuleType | None HTTPGSSAPIAuthHandler = None # type: types.ModuleType | None # type: ignore[no-redef]
if not HAS_MATCH_HOSTNAME: if not HAS_MATCH_HOSTNAME:
# The following block of code is under the terms and conditions of the # The following block of code is under the terms and conditions of the
@ -282,7 +281,7 @@ if not HAS_MATCH_HOSTNAME:
from _ssl import SSLCertVerificationError from _ssl import SSLCertVerificationError
CertificateError = SSLCertVerificationError # type: ignore[misc] CertificateError = SSLCertVerificationError # type: ignore[misc]
except ImportError: except ImportError:
class CertificateError(ValueError): class CertificateError(ValueError): # type: ignore[no-redef]
pass pass
def _dnsname_match(dn, hostname): def _dnsname_match(dn, hostname):
@ -520,7 +519,7 @@ CustomHTTPSHandler = None
HTTPSClientAuthHandler = None HTTPSClientAuthHandler = None
UnixHTTPSConnection = None UnixHTTPSConnection = None
if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler'): if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler'):
class CustomHTTPSConnection(httplib.HTTPSConnection): class CustomHTTPSConnection(httplib.HTTPSConnection): # type: ignore[no-redef]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
httplib.HTTPSConnection.__init__(self, *args, **kwargs) httplib.HTTPSConnection.__init__(self, *args, **kwargs)
self.context = None self.context = None
@ -555,7 +554,7 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
else: else:
self.sock = ssl.wrap_socket(sock, keyfile=self.key_file, certfile=self.cert_file, ssl_version=PROTOCOL) self.sock = ssl.wrap_socket(sock, keyfile=self.key_file, certfile=self.cert_file, ssl_version=PROTOCOL)
class CustomHTTPSHandler(urllib_request.HTTPSHandler): class CustomHTTPSHandler(urllib_request.HTTPSHandler): # type: ignore[no-redef]
def https_open(self, req): def https_open(self, req):
kwargs = {} kwargs = {}
@ -571,7 +570,7 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
https_request = AbstractHTTPHandler.do_request_ https_request = AbstractHTTPHandler.do_request_
class HTTPSClientAuthHandler(urllib_request.HTTPSHandler): class HTTPSClientAuthHandler(urllib_request.HTTPSHandler): # type: ignore[no-redef]
'''Handles client authentication via cert/key '''Handles client authentication via cert/key
This is a fairly lightweight extension on HTTPSHandler, and can be used This is a fairly lightweight extension on HTTPSHandler, and can be used
@ -611,7 +610,7 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
yield yield
httplib.HTTPConnection.connect = _connect httplib.HTTPConnection.connect = _connect
class UnixHTTPSConnection(httplib.HTTPSConnection): class UnixHTTPSConnection(httplib.HTTPSConnection): # type: ignore[no-redef]
def __init__(self, unix_socket): def __init__(self, unix_socket):
self._unix_socket = unix_socket self._unix_socket = unix_socket

@ -75,7 +75,7 @@ import types
try: try:
import typing as t import typing as t
except ImportError: except ImportError:
t = None # type: types.ModuleType | None t = None # type: types.ModuleType | None # type: ignore[no-redef]
from ansible.module_utils.basic import ( from ansible.module_utils.basic import (
AnsibleModule, AnsibleModule,

@ -458,7 +458,7 @@ def _have_pip_module(): # type: () -> bool
try: try:
import importlib import importlib
except ImportError: except ImportError:
importlib = None # type: types.ModuleType | None importlib = None # type: types.ModuleType | None # type: ignore[no-redef]
if importlib: if importlib:
# noinspection PyBroadException # noinspection PyBroadException

@ -139,6 +139,7 @@ lib/ansible/module_utils/six/__init__.py no-dict-iterkeys
lib/ansible/module_utils/six/__init__.py no-dict-itervalues lib/ansible/module_utils/six/__init__.py no-dict-itervalues
lib/ansible/module_utils/six/__init__.py pylint:self-assigning-variable lib/ansible/module_utils/six/__init__.py pylint:self-assigning-variable
lib/ansible/module_utils/six/__init__.py replace-urlopen lib/ansible/module_utils/six/__init__.py replace-urlopen
lib/ansible/module_utils/urls.py pylint:arguments-renamed
lib/ansible/module_utils/urls.py pylint:disallowed-name lib/ansible/module_utils/urls.py pylint:disallowed-name
lib/ansible/module_utils/urls.py replace-urlopen lib/ansible/module_utils/urls.py replace-urlopen
lib/ansible/parsing/vault/__init__.py pylint:disallowed-name lib/ansible/parsing/vault/__init__.py pylint:disallowed-name

Loading…
Cancel
Save