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:
import typing as t
except ImportError:
t = None # type: types.ModuleType | None
t = None # type: types.ModuleType | None # type: ignore[no-redef]
HAS_LIBYAML = False
try:
@ -38,9 +38,9 @@ else:
Parser = _yaml.cyaml.CParser
HAS_LIBYAML = True
except AttributeError:
SafeLoader = _yaml.SafeLoader # type: t.Type[_yaml.CSafeLoader] | t.Type[_yaml.SafeLoader]
SafeDumper = _yaml.SafeDumper # type: t.Type[_yaml.CSafeDumper] | t.Type[_yaml.SafeDumper]
Parser = _yaml.parser.Parser # type: t.Type[_yaml.cyaml.CParser] | t.Type[_yaml.parser.Parser]
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] # type: ignore[no-redef]
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_all = _partial(_yaml.load_all, Loader=SafeLoader)

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

@ -45,13 +45,13 @@ try:
except ImportError:
try:
# backport package installed in the system
import selectors2 as _system_selectors
import selectors2 as _system_selectors # type: ignore[no-redef]
except ImportError:
_system_selectors = None # type: types.ModuleType | None
_system_selectors = None # type: types.ModuleType | None # type: ignore[no-redef]
if _system_selectors:
selectors = _system_selectors
else:
# 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

@ -33,7 +33,7 @@ import types
try:
import typing as t
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

@ -66,10 +66,9 @@ try:
import httplib
except ImportError:
# 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.urllib.request as urllib_request
import ansible.module_utils.six.moves.urllib.error as urllib_error
from ansible.module_utils.common.collections import Mapping
@ -84,8 +83,8 @@ try:
from urllib.request import AbstractHTTPHandler, BaseHandler
except ImportError:
# python2
import urllib2 as urllib_request
from urllib2 import AbstractHTTPHandler, BaseHandler
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
@ -269,7 +268,7 @@ try:
except ImportError:
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:
# 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
CertificateError = SSLCertVerificationError # type: ignore[misc]
except ImportError:
class CertificateError(ValueError):
class CertificateError(ValueError): # type: ignore[no-redef]
pass
def _dnsname_match(dn, hostname):
@ -520,7 +519,7 @@ CustomHTTPSHandler = None
HTTPSClientAuthHandler = None
UnixHTTPSConnection = None
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):
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
self.context = None
@ -555,7 +554,7 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
else:
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):
kwargs = {}
@ -571,7 +570,7 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
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
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
httplib.HTTPConnection.connect = _connect
class UnixHTTPSConnection(httplib.HTTPSConnection):
class UnixHTTPSConnection(httplib.HTTPSConnection): # type: ignore[no-redef]
def __init__(self, unix_socket):
self._unix_socket = unix_socket

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

@ -458,7 +458,7 @@ def _have_pip_module(): # type: () -> bool
try:
import importlib
except ImportError:
importlib = None # type: types.ModuleType | None
importlib = None # type: types.ModuleType | None # type: ignore[no-redef]
if importlib:
# 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 pylint:self-assigning-variable
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 replace-urlopen
lib/ansible/parsing/vault/__init__.py pylint:disallowed-name

Loading…
Cancel
Save