Fix type hints and variable usage in modules. (#77184)

* Remove unused variables.
* Fix conflicting variable name.
* Add type hints.
pull/77185/head
Matt Clay 3 years ago committed by GitHub
parent 6de04e8be6
commit 35ef2af0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -70,11 +70,12 @@ import os
import platform
import socket
import traceback
import types
try:
import typing as t
except ImportError:
t = None
t = None # type: types.ModuleType | None
from ansible.module_utils.basic import (
AnsibleModule,
@ -657,7 +658,7 @@ class SLESHostname(Hostname):
distribution_version = get_distribution_version()
# cast to float may raise ValueError on non SLES, we use float for a little more safety over int
if distribution_version and 10 <= float(distribution_version) <= 12:
strategy_class = SLESStrategy
strategy_class = SLESStrategy # type: t.Type[BaseStrategy]
else:
raise ValueError()
except ValueError:

@ -272,6 +272,8 @@ import tempfile
import operator
import shlex
import traceback
import types
from ansible.module_utils.compat.version import LooseVersion
SETUPTOOLS_IMP_ERR = None
@ -456,7 +458,7 @@ def _have_pip_module(): # type: () -> bool
try:
import importlib
except ImportError:
importlib = None
importlib = None # type: types.ModuleType | None
if importlib:
# noinspection PyBroadException

@ -499,7 +499,7 @@ class User(object):
platform = 'Generic'
distribution = None # type: str | None
PASSWORDFILE = '/etc/passwd'
SHADOWFILE = '/etc/shadow'
SHADOWFILE = '/etc/shadow' # type: str | None
SHADOWFILE_EXPIRE_INDEX = 7
LOGIN_DEFS = '/etc/login.defs'
DATE_FORMAT = '%Y-%m-%d'
@ -1167,11 +1167,11 @@ class User(object):
out_buffer = b''
err_buffer = b''
while p.poll() is None:
r, w, e = select.select([master_out_fd, master_err_fd], [], [], 1)
r_list = select.select([master_out_fd, master_err_fd], [], [], 1)[0]
first_prompt = b'Enter passphrase (empty for no passphrase):'
second_prompt = b'Enter same passphrase again'
prompt = first_prompt
for fd in r:
for fd in r_list:
if fd == master_out_fd:
chunk = os.read(master_out_fd, 10240)
out_buffer += chunk

@ -603,7 +603,7 @@ def main():
matched = False
while datetime.datetime.utcnow() < end:
max_timeout = math.ceil(_timedelta_total_seconds(end - datetime.datetime.utcnow()))
(readable, w, e) = select.select([s], [], [], max_timeout)
readable = select.select([s], [], [], max_timeout)[0]
if not readable:
# No new data. Probably means our timeout
# expired

@ -759,12 +759,12 @@ class YumModule(YumDnf):
else:
raise
if not pkgs:
e, m, _ = self.yum_base.pkgSack.matchPackageNames([req_spec])
pkgs.extend(e)
pkgs.extend(m)
e, m, _ = self.yum_base.rpmdb.matchPackageNames([req_spec])
pkgs.extend(e)
pkgs.extend(m)
exact_matches, glob_matches = self.yum_base.pkgSack.matchPackageNames([req_spec])[0:2]
pkgs.extend(exact_matches)
pkgs.extend(glob_matches)
exact_matches, glob_matches = self.yum_base.rpmdb.matchPackageNames([req_spec])[0:2]
pkgs.extend(exact_matches)
pkgs.extend(glob_matches)
except Exception as e:
self.module.fail_json(msg="Failure talking to yum: %s" % to_native(e))

Loading…
Cancel
Save