From f2a783643de61cac1ff3288b40241e5ce6e1ddc8 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 25 Jan 2022 18:25:44 +0000 Subject: [PATCH] Update to latest ``pyupgrade`` hook. Stop skipping it on CI. Signed-off-by: Pedro Algarvio --- .github/workflows/pre-commit.yml | 2 +- .pre-commit-config.yaml | 6 ++---- doc/_ext/saltrepo.py | 1 - doc/_ext/youtube.py | 6 ++---- salt/auth/__init__.py | 4 +--- salt/beacons/twilio_txt_msg.py | 2 +- salt/cloud/clouds/linode.py | 6 ++---- salt/cloud/libcloudfuncs.py | 10 ++++------ salt/grains/core.py | 12 ++++++------ salt/modules/aptpkg.py | 6 +++--- salt/modules/bcache.py | 4 ++-- salt/modules/boto_asg.py | 2 +- salt/modules/boto_ec2.py | 4 ++-- salt/modules/btrfs.py | 2 +- salt/modules/dockercompose.py | 2 +- salt/modules/dockermod.py | 4 ++-- salt/modules/file.py | 4 ++-- salt/modules/inspectlib/query.py | 4 ++-- salt/modules/kernelpkg_linux_apt.py | 2 +- salt/modules/linux_shadow.py | 5 +---- salt/modules/lxc.py | 2 +- salt/modules/pacmanpkg.py | 4 ++-- salt/modules/pkgin.py | 4 ++-- salt/modules/pw_user.py | 2 +- salt/modules/rh_ip.py | 2 +- salt/modules/runit.py | 2 +- salt/modules/solaris_user.py | 2 +- salt/modules/splunk_search.py | 2 +- salt/modules/twilio_notify.py | 2 +- salt/modules/useradd.py | 2 +- salt/modules/virt.py | 6 +----- salt/modules/virtualenv_mod.py | 2 +- salt/modules/win_iis.py | 2 +- salt/modules/win_pkg.py | 2 +- salt/modules/xfs.py | 2 +- salt/modules/yumpkg.py | 6 +++--- salt/modules/zypperpkg.py | 12 +++++------- salt/output/table_out.py | 2 +- salt/returners/sentry_return.py | 8 +++----- salt/returners/sms_return.py | 2 +- salt/roster/cache.py | 4 ++-- salt/runners/manage.py | 4 ++-- salt/states/azurearm_compute.py | 4 ++-- salt/states/azurearm_dns.py | 12 ++++++------ salt/states/boto_iam_role.py | 2 +- salt/states/cyg.py | 4 ++-- salt/states/linux_acl.py | 8 ++++---- salt/states/pkg.py | 2 +- salt/states/pkgrepo.py | 4 ++-- salt/utils/azurearm.py | 4 ++-- salt/utils/fsutils.py | 2 +- salt/utils/platform.py | 8 ++++---- salt/utils/zeromq.py | 6 ++---- salt/version.py | 2 +- tasks/docs.py | 2 +- tests/integration/modules/test_git.py | 4 ++-- tests/pytests/functional/modules/state/test_state.py | 4 ++-- .../integration/modules/test_rpmbuild_pkgbuild.py | 2 +- tests/pytests/unit/beacons/test_twilio_txt_msg.py | 2 +- tests/pytests/unit/states/test_host.py | 10 +++++----- .../unit/utils/jinja/test_custom_extensions.py | 2 +- tests/support/mock.py | 2 +- tests/unit/fileserver/test_roots.py | 8 ++------ tests/unit/modules/test_twilio_notify.py | 2 +- tests/unit/modules/test_zcbuildout.py | 2 +- tests/unit/utils/test_data.py | 6 +++--- tests/unit/utils/test_thin.py | 2 +- 67 files changed, 121 insertions(+), 149 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 03526afe4c1..49ca9de6df5 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -47,7 +47,7 @@ jobs: - name: Check ALL Files On Branch if: github.event_name != 'pull_request' env: - SKIP: lint-salt,lint-tests,pyupgrade,remove-import-headers,rstcheck + SKIP: lint-salt,lint-tests,remove-import-headers,rstcheck run: | pre-commit run --show-diff-on-failure --color=always --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca007d7b421..0dca627f329 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1197,9 +1197,7 @@ repos: # ----- Code Formatting -------------------------------------------------------------------------------------------> - repo: https://github.com/asottile/pyupgrade - # This, for now, is meant to run when locally committing code and will be disabled(skipped) when we run pre-commit - # against all codebase to avoid MASSIVE code churn. This way, we do it in smaller chunks, a few at a time. - rev: v2.7.2 + rev: v2.31.0 hooks: - id: pyupgrade name: Drop six usage and Py2 support @@ -1207,7 +1205,7 @@ repos: exclude: > (?x)^( salt/client/ssh/ssh_py_shim.py| - salt/ext/ipaddress.py + salt/ext/.*\.py )$ - repo: https://github.com/saltstack/pre-commit-remove-import-headers diff --git a/doc/_ext/saltrepo.py b/doc/_ext/saltrepo.py index fd75ae21cee..0c1dafb4064 100644 --- a/doc/_ext/saltrepo.py +++ b/doc/_ext/saltrepo.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ saltrepo ~~~~~~~~ diff --git a/doc/_ext/youtube.py b/doc/_ext/youtube.py index 35be8c1c78a..9603a326b7a 100644 --- a/doc/_ext/youtube.py +++ b/doc/_ext/youtube.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # Taken from sphinx-contrib # https://bitbucket.org/birkenfeld/sphinx-contrib/src/a3d904f8ab24/youtube @@ -33,7 +32,6 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import division import re @@ -51,7 +49,7 @@ CONTROL_HEIGHT = 30 def get_size(d, key): if key not in d: return None - m = re.match("(\d+)(|%|px)$", d[key]) + m = re.match(r"(\d+)(|%|px)$", d[key]) if not m: raise ValueError("invalid size %r" % d[key]) return int(m.group(1)), m.group(2) or "px" @@ -134,7 +132,7 @@ class YouTube(Directive): def run(self): if "aspect" in self.options: aspect = self.options.get("aspect") - m = re.match("(\d+):(\d+)", aspect) + m = re.match(r"(\d+):(\d+)", aspect) if m is None: raise ValueError("invalid aspect ratio %r" % aspect) aspect = tuple(int(x) for x in m.groups()) diff --git a/salt/auth/__init__.py b/salt/auth/__init__.py index 2e9cff624cd..afd7ad65fa6 100644 --- a/salt/auth/__init__.py +++ b/salt/auth/__init__.py @@ -534,9 +534,7 @@ class Resolver: ) print( "Available eauth types: {}".format( - ", ".join( - sorted([k[:-5] for k in self.auth if k.endswith(".auth")]) - ) + ", ".join(sorted(k[:-5] for k in self.auth if k.endswith(".auth"))) ) ) return ret diff --git a/salt/beacons/twilio_txt_msg.py b/salt/beacons/twilio_txt_msg.py index 3010d0e980d..7ff5a361fb6 100644 --- a/salt/beacons/twilio_txt_msg.py +++ b/salt/beacons/twilio_txt_msg.py @@ -9,7 +9,7 @@ try: import twilio # Grab version, ensure elements are ints - twilio_version = tuple([int(x) for x in twilio.__version_info__]) + twilio_version = tuple(int(x) for x in twilio.__version_info__) if twilio_version > (5,): from twilio.rest import Client as TwilioRestClient else: diff --git a/salt/cloud/clouds/linode.py b/salt/cloud/clouds/linode.py index 7b90ed5de72..5d883cf938b 100644 --- a/salt/cloud/clouds/linode.py +++ b/salt/cloud/clouds/linode.py @@ -1813,10 +1813,8 @@ class LinodeAPIv3(LinodeAPI): vm_["name"], pprint.pprint( sorted( - [ - distro["LABEL"].encode(__salt_system_encoding__) - for distro in distributions - ] + distro["LABEL"].encode(__salt_system_encoding__) + for distro in distributions ) ), ) diff --git a/salt/cloud/libcloudfuncs.py b/salt/cloud/libcloudfuncs.py index dc569aac48e..ed67934b1c7 100644 --- a/salt/cloud/libcloudfuncs.py +++ b/salt/cloud/libcloudfuncs.py @@ -22,12 +22,10 @@ try: HAS_LIBCLOUD = True LIBCLOUD_VERSION_INFO = tuple( - [ - int(part) - for part in libcloud.__version__.replace("-", ".") - .replace("rc", ".") - .split(".")[:3] - ] + int(part) + for part in libcloud.__version__.replace("-", ".") + .replace("rc", ".") + .split(".")[:3] ) except ImportError: diff --git a/salt/grains/core.py b/salt/grains/core.py index bdfaa8b0504..9b2f9298ab8 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -1775,15 +1775,15 @@ def _parse_cpe_name(cpe): ret["phase"] = cpe[5] if len(cpe) > 5 else None ret["part"] = part.get(cpe[1][1:]) elif len(cpe) == 6 and cpe[1] == "2.3": # WFN to a string - ret["vendor"], ret["product"], ret["version"] = [ + ret["vendor"], ret["product"], ret["version"] = ( x if x != "*" else None for x in cpe[3:6] - ] + ) ret["phase"] = None ret["part"] = part.get(cpe[2]) elif len(cpe) > 7 and len(cpe) <= 13 and cpe[1] == "2.3": # WFN to a string - ret["vendor"], ret["product"], ret["version"], ret["phase"] = [ + ret["vendor"], ret["product"], ret["version"], ret["phase"] = ( x if x != "*" else None for x in cpe[3:7] - ] + ) ret["part"] = part.get(cpe[2]) return ret @@ -2103,9 +2103,9 @@ def os_data(): log.trace( "Getting OS name, release, and codename from distro id, version, codename" ) - (osname, osrelease, oscodename) = [ + (osname, osrelease, oscodename) = ( x.strip('"').strip("'") for x in _linux_distribution() - ] + ) # Try to assign these three names based on the lsb info, they tend to # be more accurate than what python gets from /etc/DISTRO-release. # It's worth noting that Ubuntu has patched their Python distribution diff --git a/salt/modules/aptpkg.py b/salt/modules/aptpkg.py index 7ded2944c66..f32548ae3b6 100644 --- a/salt/modules/aptpkg.py +++ b/salt/modules/aptpkg.py @@ -1472,9 +1472,9 @@ def list_pkgs( for line in out.splitlines(): cols = line.split() try: - linetype, status, name, version_num, arch = [ + linetype, status, name, version_num, arch = ( cols[x] for x in (0, 2, 3, 4, 5) - ] + ) except (ValueError, IndexError): continue if __grains__.get("cpuarch", "") == "x86_64": @@ -2997,7 +2997,7 @@ def show(*names, **kwargs): line = line.strip() if line: try: - key, val = [x.strip() for x in line.split(":", 1)] + key, val = (x.strip() for x in line.split(":", 1)) except ValueError: pass else: diff --git a/salt/modules/bcache.py b/salt/modules/bcache.py index e3a7144a2fb..b3c1a92559b 100644 --- a/salt/modules/bcache.py +++ b/salt/modules/bcache.py @@ -644,13 +644,13 @@ def super_(dev): if not line: continue - key, val = [val.strip() for val in re.split(r"[\s]+", line, maxsplit=1)] + key, val = (val.strip() for val in re.split(r"[\s]+", line, maxsplit=1)) if not (key and val): continue mval = None if " " in val: - rval, mval = [val.strip() for val in re.split(r"[\s]+", val, maxsplit=1)] + rval, mval = (val.strip() for val in re.split(r"[\s]+", val, maxsplit=1)) mval = mval[1:-1] else: rval = val diff --git a/salt/modules/boto_asg.py b/salt/modules/boto_asg.py index 08df7b7197a..7bdad75c7a0 100644 --- a/salt/modules/boto_asg.py +++ b/salt/modules/boto_asg.py @@ -188,7 +188,7 @@ def get_config(name, region=None, key=None, keyid=None, profile=None): # convert SuspendedProcess objects to names elif attr == "suspended_processes": suspended_processes = getattr(asg, attr) - ret[attr] = sorted([x.process_name for x in suspended_processes]) + ret[attr] = sorted(x.process_name for x in suspended_processes) else: ret[attr] = getattr(asg, attr) # scaling policies diff --git a/salt/modules/boto_ec2.py b/salt/modules/boto_ec2.py index ec87c8a4e77..73281ab4249 100644 --- a/salt/modules/boto_ec2.py +++ b/salt/modules/boto_ec2.py @@ -232,9 +232,9 @@ def get_eip_address_info( .. versionadded:: 2016.3.0 """ - if type(addresses) == (type("string")): + if isinstance(addresses, str): addresses = [addresses] - if type(allocation_ids) == (type("string")): + if isinstance(allocation_ids, str): allocation_ids = [allocation_ids] ret = _get_all_eip_addresses( diff --git a/salt/modules/btrfs.py b/salt/modules/btrfs.py index 606419c2a73..4a1d37fbfcb 100644 --- a/salt/modules/btrfs.py +++ b/salt/modules/btrfs.py @@ -58,7 +58,7 @@ def _parse_btrfs_info(data): for line in [line for line in data.split("\n") if line][:-1]: if line.startswith("Label:"): line = re.sub(r"Label:\s+", "", line) - label, uuid_ = [tkn.strip() for tkn in line.split("uuid:")] + label, uuid_ = (tkn.strip() for tkn in line.split("uuid:")) ret["label"] = label != "none" and label or None ret["uuid"] = uuid_ continue diff --git a/salt/modules/dockercompose.py b/salt/modules/dockercompose.py index f47100b7b48..a785b983c62 100644 --- a/salt/modules/dockercompose.py +++ b/salt/modules/dockercompose.py @@ -145,7 +145,7 @@ def __virtual__(): if HAS_DOCKERCOMPOSE: match = re.match(VERSION_RE, str(compose.__version__)) if match: - version = tuple([int(x) for x in match.group(1).split(".")]) + version = tuple(int(x) for x in match.group(1).split(".")) if version >= MIN_DOCKERCOMPOSE: return __virtualname__ return ( diff --git a/salt/modules/dockermod.py b/salt/modules/dockermod.py index db0233795f3..199f10f2773 100644 --- a/salt/modules/dockermod.py +++ b/salt/modules/dockermod.py @@ -2505,11 +2505,11 @@ def version(): if "Version" in ret: match = version_re.match(str(ret["Version"])) if match: - ret["VersionInfo"] = tuple([int(x) for x in match.group(1).split(".")]) + ret["VersionInfo"] = tuple(int(x) for x in match.group(1).split(".")) if "ApiVersion" in ret: match = version_re.match(str(ret["ApiVersion"])) if match: - ret["ApiVersionInfo"] = tuple([int(x) for x in match.group(1).split(".")]) + ret["ApiVersionInfo"] = tuple(int(x) for x in match.group(1).split(".")) return ret diff --git a/salt/modules/file.py b/salt/modules/file.py index d62c38f99cd..6673e4fca8b 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -874,9 +874,9 @@ def get_source_sum( # The source_hash is a hash expression ret = {} try: - ret["hash_type"], ret["hsum"] = [ + ret["hash_type"], ret["hsum"] = ( x.strip() for x in source_hash.split("=", 1) - ] + ) except AttributeError: _invalid_source_hash_format() except ValueError: diff --git a/salt/modules/inspectlib/query.py b/salt/modules/inspectlib/query.py index 079cc291725..bd01e67ba7a 100644 --- a/salt/modules/inspectlib/query.py +++ b/salt/modules/inspectlib/query.py @@ -53,9 +53,9 @@ class SysInfo: log.error(msg) raise SIException(msg) - devpath, blocks, used, available, used_p, mountpoint = [ + devpath, blocks, used, available, used_p, mountpoint = ( elm for elm in out["stdout"].split(os.linesep)[-1].split(" ") if elm - ] + ) return { "device": devpath, "blocks": blocks, diff --git a/salt/modules/kernelpkg_linux_apt.py b/salt/modules/kernelpkg_linux_apt.py index feb8045cb4a..2534565d568 100644 --- a/salt/modules/kernelpkg_linux_apt.py +++ b/salt/modules/kernelpkg_linux_apt.py @@ -74,7 +74,7 @@ def list_installed(): prefix_len = len(_package_prefix()) + 1 return sorted( - [pkg[prefix_len:] for pkg in result], key=functools.cmp_to_key(_cmp_version) + (pkg[prefix_len:] for pkg in result), key=functools.cmp_to_key(_cmp_version) ) diff --git a/salt/modules/linux_shadow.py b/salt/modules/linux_shadow.py index e9e5483ef19..01de86b2f87 100644 --- a/salt/modules/linux_shadow.py +++ b/salt/modules/linux_shadow.py @@ -519,10 +519,7 @@ def list_users(root=None): getspall = functools.partial(spwd.getspall) return sorted( - [ - user.sp_namp if hasattr(user, "sp_namp") else user.sp_nam - for user in getspall() - ] + user.sp_namp if hasattr(user, "sp_namp") else user.sp_nam for user in getspall() ) diff --git a/salt/modules/lxc.py b/salt/modules/lxc.py index 9710f83262b..28d602dd784 100644 --- a/salt/modules/lxc.py +++ b/salt/modules/lxc.py @@ -983,7 +983,7 @@ def _get_veths(net_data): if sitem.startswith("#") or not sitem: continue elif "=" in item: - item = tuple([a.strip() for a in item.split("=", 1)]) + item = tuple(a.strip() for a in item.split("=", 1)) if item[0] == "lxc.network.type": current_nic = salt.utils.odict.OrderedDict() if item[0] == "lxc.network.name": diff --git a/salt/modules/pacmanpkg.py b/salt/modules/pacmanpkg.py index 27fedea394c..a03be2901cb 100644 --- a/salt/modules/pacmanpkg.py +++ b/salt/modules/pacmanpkg.py @@ -1036,7 +1036,7 @@ def list_repo_pkgs(*args, **kwargs): # Sort versions newest to oldest for pkgname in ret[reponame]: sorted_versions = sorted( - [_LooseVersion(x) for x in ret[reponame][pkgname]], reverse=True + (_LooseVersion(x) for x in ret[reponame][pkgname]), reverse=True ) ret[reponame][pkgname] = [x.vstring for x in sorted_versions] return ret @@ -1047,7 +1047,7 @@ def list_repo_pkgs(*args, **kwargs): byrepo_ret.setdefault(pkgname, []).extend(ret[reponame][pkgname]) for pkgname in byrepo_ret: sorted_versions = sorted( - [_LooseVersion(x) for x in byrepo_ret[pkgname]], reverse=True + (_LooseVersion(x) for x in byrepo_ret[pkgname]), reverse=True ) byrepo_ret[pkgname] = [x.vstring for x in sorted_versions] return byrepo_ret diff --git a/salt/modules/pkgin.py b/salt/modules/pkgin.py index 4319ffd96d6..c27b6ed8fce 100644 --- a/salt/modules/pkgin.py +++ b/salt/modules/pkgin.py @@ -72,7 +72,7 @@ def _supports_regex(): """ Check support of regexp """ - return tuple([int(i) for i in _get_version()]) > (0, 5) + return tuple(int(i) for i in _get_version()) > (0, 5) @decorators.memoize @@ -80,7 +80,7 @@ def _supports_parsing(): """ Check support of parsing """ - return tuple([int(i) for i in _get_version()]) > (0, 6) + return tuple(int(i) for i in _get_version()) > (0, 6) def __virtual__(): diff --git a/salt/modules/pw_user.py b/salt/modules/pw_user.py index 3e786e931e3..6506452db56 100644 --- a/salt/modules/pw_user.py +++ b/salt/modules/pw_user.py @@ -503,7 +503,7 @@ def list_users(): salt '*' user.list_users """ - return sorted([user.pw_name for user in pwd.getpwall()]) + return sorted(user.pw_name for user in pwd.getpwall()) def rename(name, new_name): diff --git a/salt/modules/rh_ip.py b/salt/modules/rh_ip.py index 4eddf9ac5d1..44202b390ea 100644 --- a/salt/modules/rh_ip.py +++ b/salt/modules/rh_ip.py @@ -712,7 +712,7 @@ def _parse_settings_eth(opts, iface_type, enabled, iface): result["ipaddrs"] = [] for opt in opts["ipaddrs"]: if salt.utils.validate.net.ipv4_addr(opt): - ip, prefix = [i.strip() for i in opt.split("/")] + ip, prefix = (i.strip() for i in opt.split("/")) result["ipaddrs"].append({"ipaddr": ip, "prefix": prefix}) else: msg = "ipv4 CIDR is invalid" diff --git a/salt/modules/runit.py b/salt/modules/runit.py index 404570ff946..333c4ffd67b 100644 --- a/salt/modules/runit.py +++ b/salt/modules/runit.py @@ -383,7 +383,7 @@ def _get_svc_list(name="*", status=None): 'DISABLED' : available service that is not enabled 'ENABLED' : enabled service (whether started on boot or not) """ - return sorted([os.path.basename(el) for el in _get_svc_path(name, status)]) + return sorted(os.path.basename(el) for el in _get_svc_path(name, status)) def get_svc_alias(): diff --git a/salt/modules/solaris_user.py b/salt/modules/solaris_user.py index b6911ff60db..e8d7d0b2bc4 100644 --- a/salt/modules/solaris_user.py +++ b/salt/modules/solaris_user.py @@ -443,7 +443,7 @@ def list_users(): salt '*' user.list_users """ - return sorted([user.pw_name for user in pwd.getpwall()]) + return sorted(user.pw_name for user in pwd.getpwall()) def rename(name, new_name): diff --git a/salt/modules/splunk_search.py b/salt/modules/splunk_search.py index b8f6e115e88..58a64b2dc1d 100644 --- a/salt/modules/splunk_search.py +++ b/salt/modules/splunk_search.py @@ -270,7 +270,7 @@ def list_all( results = OrderedDict() # sort the splunk searches by name, so we get consistent output - searches = sorted([(s.name, s) for s in client.saved_searches]) + searches = sorted((s.name, s) for s in client.saved_searches) for name, search in searches: if app and search.access.app != app: continue diff --git a/salt/modules/twilio_notify.py b/salt/modules/twilio_notify.py index dc290718294..5d28e7922fa 100644 --- a/salt/modules/twilio_notify.py +++ b/salt/modules/twilio_notify.py @@ -26,7 +26,7 @@ try: import twilio # Grab version, ensure elements are ints - twilio_version = tuple([int(x) for x in twilio.__version_info__]) + twilio_version = tuple(int(x) for x in twilio.__version_info__) if twilio_version > (5,): TWILIO_5 = False from twilio.rest import Client as TwilioRestClient diff --git a/salt/modules/useradd.py b/salt/modules/useradd.py index 211e83ac1c9..00362ebfc3c 100644 --- a/salt/modules/useradd.py +++ b/salt/modules/useradd.py @@ -874,7 +874,7 @@ def list_users(root=None): else: getpwall = functools.partial(pwd.getpwall) - return sorted([user.pw_name for user in getpwall()]) + return sorted(user.pw_name for user in getpwall()) def rename(name, new_name, root=None): diff --git a/salt/modules/virt.py b/salt/modules/virt.py index 0e40f94f776..a5aa919adb7 100644 --- a/salt/modules/virt.py +++ b/salt/modules/virt.py @@ -1780,11 +1780,7 @@ def _fill_disk_filename(conn, vm_name, disk, hypervisor, pool_caps): int(re.sub("[a-z]+", "", vol_name)) for vol_name in all_volumes ] or [0] index = min( - [ - idx - for idx in range(1, max(indexes) + 2) - if idx not in indexes - ] + idx for idx in range(1, max(indexes) + 2) if idx not in indexes ) disk["filename"] = "{}{}".format(os.path.basename(device), index) diff --git a/salt/modules/virtualenv_mod.py b/salt/modules/virtualenv_mod.py index 726057d75cf..a94a22b00eb 100644 --- a/salt/modules/virtualenv_mod.py +++ b/salt/modules/virtualenv_mod.py @@ -67,7 +67,7 @@ def virtualenv_ver(venv_bin, user=None, **kwargs): [x for x in ret["stdout"].strip().split() if re.search(r"^\d.\d*", x)] ) virtualenv_version_info = tuple( - [int(i) for i in re.sub(r"(rc|\+ds).*$", "", version).split(".")] + int(i) for i in re.sub(r"(rc|\+ds).*$", "", version).split(".") ) return virtualenv_version_info diff --git a/salt/modules/win_iis.py b/salt/modules/win_iis.py index 8c1bbf10853..f555062681c 100644 --- a/salt/modules/win_iis.py +++ b/salt/modules/win_iis.py @@ -247,7 +247,7 @@ def list_sites(): filtered_binding.update({key.lower(): binding[key]}) binding_info = binding["bindingInformation"].split(":", 2) - ipaddress, port, hostheader = [element.strip() for element in binding_info] + ipaddress, port, hostheader = (element.strip() for element in binding_info) filtered_binding.update( {"hostheader": hostheader, "ipaddress": ipaddress, "port": port} ) diff --git a/salt/modules/win_pkg.py b/salt/modules/win_pkg.py index a0e8a39659b..c85c1d46e3a 100644 --- a/salt/modules/win_pkg.py +++ b/salt/modules/win_pkg.py @@ -1316,7 +1316,7 @@ def _get_source_sum(source_hash, file_path, saltenv): ) raise SaltInvocationError(invalid_hash_msg) - ret["hash_type"], ret["hsum"] = [item.strip().lower() for item in items] + ret["hash_type"], ret["hsum"] = (item.strip().lower() for item in items) return ret diff --git a/salt/modules/xfs.py b/salt/modules/xfs.py index a82496cd85b..60329c9a13a 100644 --- a/salt/modules/xfs.py +++ b/salt/modules/xfs.py @@ -288,7 +288,7 @@ def _xfs_prune_output(out, uuid): cnt.append(line) for kset in [e for e in cnt[1:] if ":" in e]: - key, val = [t.strip() for t in kset.split(":", 1)] + key, val = (t.strip() for t in kset.split(":", 1)) data[key.lower().replace(" ", "_")] = val return data.get("uuid") == uuid and data or {} diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py index cf684e20f73..b977efdbd05 100644 --- a/salt/modules/yumpkg.py +++ b/salt/modules/yumpkg.py @@ -1010,7 +1010,7 @@ def list_repo_pkgs(*args, **kwargs): # Sort versions newest to oldest for pkgname in ret[reponame]: sorted_versions = sorted( - [_LooseVersion(x) for x in ret[reponame][pkgname]], reverse=True + (_LooseVersion(x) for x in ret[reponame][pkgname]), reverse=True ) ret[reponame][pkgname] = [x.vstring for x in sorted_versions] return ret @@ -1021,7 +1021,7 @@ def list_repo_pkgs(*args, **kwargs): byrepo_ret.setdefault(pkgname, []).extend(ret[reponame][pkgname]) for pkgname in byrepo_ret: sorted_versions = sorted( - [_LooseVersion(x) for x in byrepo_ret[pkgname]], reverse=True + (_LooseVersion(x) for x in byrepo_ret[pkgname]), reverse=True ) byrepo_ret[pkgname] = [x.vstring for x in sorted_versions] return byrepo_ret @@ -2566,7 +2566,7 @@ def group_info(name, expand=False, ignore_groups=None): g_info = {} for line in salt.utils.itertools.split(out, "\n"): try: - key, value = [x.strip() for x in line.split(":")] + key, value = (x.strip() for x in line.split(":")) g_info[key.lower()] = value except ValueError: continue diff --git a/salt/modules/zypperpkg.py b/salt/modules/zypperpkg.py index 13f5487a86d..504d87e7dc0 100644 --- a/salt/modules/zypperpkg.py +++ b/salt/modules/zypperpkg.py @@ -435,10 +435,8 @@ class Wildcard: self.name = pkg_name self._set_version(pkg_version) # Dissects possible operator versions = sorted( - [ - LooseVersion(vrs) - for vrs in self._get_scope_versions(self._get_available_versions()) - ] + LooseVersion(vrs) + for vrs in self._get_scope_versions(self._get_available_versions()) ) return versions and "{}{}".format(self._op or "", versions[-1]) or None @@ -1080,7 +1078,7 @@ def list_repo_pkgs(*args, **kwargs): # Sort versions newest to oldest for pkgname in ret[reponame]: sorted_versions = sorted( - [LooseVersion(x) for x in ret[reponame][pkgname]], reverse=True + (LooseVersion(x) for x in ret[reponame][pkgname]), reverse=True ) ret[reponame][pkgname] = [x.vstring for x in sorted_versions] return ret @@ -1091,7 +1089,7 @@ def list_repo_pkgs(*args, **kwargs): byrepo_ret.setdefault(pkgname, []).extend(ret[reponame][pkgname]) for pkgname in byrepo_ret: sorted_versions = sorted( - [LooseVersion(x) for x in byrepo_ret[pkgname]], reverse=True + (LooseVersion(x) for x in byrepo_ret[pkgname]), reverse=True ) byrepo_ret[pkgname] = [x.vstring for x in sorted_versions] return byrepo_ret @@ -2047,7 +2045,7 @@ def list_locks(root=None): for element in [el for el in meta if el]: if ":" in element: lock.update( - dict([tuple([i.strip() for i in element.split(":", 1)])]) + dict([tuple(i.strip() for i in element.split(":", 1))]) ) if lock.get("solvable_name"): locks[lock.pop("solvable_name")] = lock diff --git a/salt/output/table_out.py b/salt/output/table_out.py index 133d094c4c0..730e0cb2df8 100644 --- a/salt/output/table_out.py +++ b/salt/output/table_out.py @@ -155,7 +155,7 @@ class TableDisplay: columns = map(lambda *args: args, *reduce(operator.add, logical_rows)) - max_widths = [max([len(str(item)) for item in column]) for column in columns] + max_widths = [max(len(str(item)) for item in column) for column in columns] row_separator = self.row_delimiter * ( len(self.prefix) + len(self.suffix) diff --git a/salt/returners/sentry_return.py b/salt/returners/sentry_return.py index 97221d635a1..0b660392ef0 100644 --- a/salt/returners/sentry_return.py +++ b/salt/returners/sentry_return.py @@ -112,11 +112,9 @@ def _get_message(ret): if isinstance(kwargs, dict): kwarg_string = " ".join( sorted( - [ - "{}={}".format(k, v) - for k, v in kwargs.items() - if not k.startswith("_") - ] + "{}={}".format(k, v) + for k, v in kwargs.items() + if not k.startswith("_") ) ) return "salt func: {fun} {argstr} {kwargstr}".format( diff --git a/salt/returners/sms_return.py b/salt/returners/sms_return.py index c9008b81316..883a6a7eae4 100644 --- a/salt/returners/sms_return.py +++ b/salt/returners/sms_return.py @@ -37,7 +37,7 @@ try: import twilio # Grab version, ensure elements are ints - twilio_version = tuple([int(x) for x in twilio.__version_info__]) + twilio_version = tuple(int(x) for x in twilio.__version_info__) if twilio_version > (5,): TWILIO_5 = False from twilio.rest import Client as TwilioRestClient diff --git a/salt/roster/cache.py b/salt/roster/cache.py index 694f8c48a5e..a6a117d2d8e 100644 --- a/salt/roster/cache.py +++ b/salt/roster/cache.py @@ -173,8 +173,8 @@ def _load_minion(minion_id, cache): pillar = {} addrs = { - 4: sorted([ipaddress.IPv4Address(addr) for addr in grains.get("ipv4", [])]), - 6: sorted([ipaddress.IPv6Address(addr) for addr in grains.get("ipv6", [])]), + 4: sorted(ipaddress.IPv4Address(addr) for addr in grains.get("ipv4", [])), + 6: sorted(ipaddress.IPv6Address(addr) for addr in grains.get("ipv6", [])), } mine = cache.fetch("minions/{}".format(minion_id), "mine") diff --git a/salt/runners/manage.py b/salt/runners/manage.py index acc9653af4c..a4786106594 100644 --- a/salt/runners/manage.py +++ b/salt/runners/manage.py @@ -797,10 +797,10 @@ def bootstrap_psexec( '>(Salt-Minion-(.+?)-(.+)-Setup.exe)(.*?)\\s*<' ) source_list = sorted( - [ + ( [path, ver, plat, time.strptime(date, "%d-%b-%Y %H:%M")] for path, ver, plat, date in salty_rx.findall(source) - ], + ), key=operator.itemgetter(3), reverse=True, ) diff --git a/salt/states/azurearm_compute.py b/salt/states/azurearm_compute.py index 3b3277f8db7..c85c29126c6 100644 --- a/salt/states/azurearm_compute.py +++ b/salt/states/azurearm_compute.py @@ -212,9 +212,9 @@ def availability_set_present( return ret aset_vms = aset.get("virtual_machines", []) remote_vms = sorted( - [vm["id"].split("/")[-1].lower() for vm in aset_vms if "id" in aset_vms] + vm["id"].split("/")[-1].lower() for vm in aset_vms if "id" in aset_vms ) - local_vms = sorted([vm.lower() for vm in virtual_machines or []]) + local_vms = sorted(vm.lower() for vm in virtual_machines or []) if local_vms != remote_vms: ret["changes"]["virtual_machines"] = { "old": aset_vms, diff --git a/salt/states/azurearm_dns.py b/salt/states/azurearm_dns.py index a9d49ceb407..cfc8ce85637 100644 --- a/salt/states/azurearm_dns.py +++ b/salt/states/azurearm_dns.py @@ -237,10 +237,10 @@ def zone_present( return ret reg_vnets = zone.get("registration_virtual_networks", []) remote_reg_vnets = sorted( - [vnet["id"].lower() for vnet in reg_vnets if "id" in vnet] + vnet["id"].lower() for vnet in reg_vnets if "id" in vnet ) local_reg_vnets = sorted( - [vnet.lower() for vnet in registration_virtual_networks or []] + vnet.lower() for vnet in registration_virtual_networks or [] ) if local_reg_vnets != remote_reg_vnets: ret["changes"]["registration_virtual_networks"] = { @@ -259,10 +259,10 @@ def zone_present( return ret res_vnets = zone.get("resolution_virtual_networks", []) remote_res_vnets = sorted( - [vnet["id"].lower() for vnet in res_vnets if "id" in vnet] + vnet["id"].lower() for vnet in res_vnets if "id" in vnet ) local_res_vnets = sorted( - [vnet.lower() for vnet in resolution_virtual_networks or []] + vnet.lower() for vnet in resolution_virtual_networks or [] ) if local_res_vnets != remote_res_vnets: ret["changes"]["resolution_virtual_networks"] = { @@ -582,9 +582,9 @@ def record_set_present( " dictionaries!".format(record_str) ) return ret - local, remote = [ + local, remote = ( sorted(config) for config in (record, rec_set[record_str]) - ] + ) for val in local: for key in val: local_val = val[key] diff --git a/salt/states/boto_iam_role.py b/salt/states/boto_iam_role.py index f61c117578e..67c41f760a0 100644 --- a/salt/states/boto_iam_role.py +++ b/salt/states/boto_iam_role.py @@ -358,7 +358,7 @@ def _sort_policy(doc): the likelihood of false negatives. """ if isinstance(doc, list): - return sorted([_sort_policy(i) for i in doc]) + return sorted(_sort_policy(i) for i in doc) elif isinstance(doc, (dict, OrderedDict)): return {k: _sort_policy(v) for k, v in doc.items()} return doc diff --git a/salt/states/cyg.py b/salt/states/cyg.py index 97f54c887f0..957b194c724 100644 --- a/salt/states/cyg.py +++ b/salt/states/cyg.py @@ -222,9 +222,9 @@ class DictDiffer: Iitialize the differ. """ self.current_dict, self.past_dict = current_dict, past_dict - self.current_keys, self.past_keys = [ + self.current_keys, self.past_keys = ( set(d.keys()) for d in (current_dict, past_dict) - ] + ) self.intersect = self.current_keys.intersection(self.past_keys) def same(self): diff --git a/salt/states/linux_acl.py b/salt/states/linux_acl.py index 556204dab1d..c45c9383487 100644 --- a/salt/states/linux_acl.py +++ b/salt/states/linux_acl.py @@ -145,7 +145,7 @@ def present(name, acl_type, acl_name="", perms="", recurse=False, force=False): user = None if user: - octal_sum = sum([_octal.get(i, i) for i in perms]) + octal_sum = sum(_octal.get(i, i) for i in perms) need_refresh = False # If recursive check all paths retrieved via acl.getfacl if recurse: @@ -169,7 +169,7 @@ def present(name, acl_type, acl_name="", perms="", recurse=False, force=False): break # Check the permissions from the already located file - elif user[_search_name]["octal"] == sum([_octal.get(i, i) for i in perms]): + elif user[_search_name]["octal"] == sum(_octal.get(i, i) for i in perms): need_refresh = False # If they don't match then refresh else: @@ -402,7 +402,7 @@ def list_present(name, acl_type, acl_names=None, perms="", recurse=False, force= ret = {"name": name, "result": True, "changes": {}, "comment": ""} _octal = {"r": 4, "w": 2, "x": 1, "-": 0} - _octal_perms = sum([_octal.get(i, i) for i in perms]) + _octal_perms = sum(_octal.get(i, i) for i in perms) if not os.path.exists(name): ret["comment"] = "{} does not exist".format(name) ret["result"] = False @@ -475,7 +475,7 @@ def list_present(name, acl_type, acl_names=None, perms="", recurse=False, force= for count, search_name in enumerate(_search_names): if search_name in users: if users[search_name]["octal"] == sum( - [_octal.get(i, i) for i in perms] + _octal.get(i, i) for i in perms ): ret["comment"] = "Permissions are in the desired state" else: diff --git a/salt/states/pkg.py b/salt/states/pkg.py index 2c2a7e56551..2fd57c84812 100644 --- a/salt/states/pkg.py +++ b/salt/states/pkg.py @@ -3003,7 +3003,7 @@ def _uninstall( } comments = [] - not_installed = sorted([x for x in pkg_params if x not in targets]) + not_installed = sorted(x for x in pkg_params if x not in targets) if not_installed: comments.append( "The following packages were not installed: {}".format( diff --git a/salt/states/pkgrepo.py b/salt/states/pkgrepo.py index f395dec1edc..c0cc153f87b 100644 --- a/salt/states/pkgrepo.py +++ b/salt/states/pkgrepo.py @@ -440,9 +440,9 @@ def managed(name, ppa=None, copr=None, **kwargs): # split the line and sort everything after the URL sanitizedsplit = sanitizedkwargs[kwarg].split() sanitizedsplit[3:] = sorted(sanitizedsplit[3:]) - reposplit, _, pre_comments = [ + reposplit, _, pre_comments = ( x.strip() for x in pre[kwarg].partition("#") - ] + ) reposplit = reposplit.split() reposplit[3:] = sorted(reposplit[3:]) if sanitizedsplit != reposplit: diff --git a/salt/utils/azurearm.py b/salt/utils/azurearm.py index 87985a2769f..396ec15ec44 100644 --- a/salt/utils/azurearm.py +++ b/salt/utils/azurearm.py @@ -306,9 +306,9 @@ def compare_list_of_dicts(old, new, convert_id_to_name=None): return ret try: - local_configs, remote_configs = [ + local_configs, remote_configs = ( sorted(config, key=itemgetter("name")) for config in (new, old) - ] + ) except TypeError: ret["comment"] = "configurations must be provided as a list of dictionaries!" return ret diff --git a/salt/utils/fsutils.py b/salt/utils/fsutils.py index 106adb55b02..7b0eb084f64 100644 --- a/salt/utils/fsutils.py +++ b/salt/utils/fsutils.py @@ -96,7 +96,7 @@ def _blkid(fs_type=None): dev_name = device.pop(0)[:-1] data[dev_name] = dict() for k_set in device: - ks_key, ks_value = [elm.replace('"', "") for elm in k_set.split("=")] + ks_key, ks_value = (elm.replace('"', "") for elm in k_set.split("=")) data[dev_name][ks_key.lower()] = ks_value if fs_type: diff --git a/salt/utils/platform.py b/salt/utils/platform.py index 0bbdfed3ae4..2f75691d6f3 100644 --- a/salt/utils/platform.py +++ b/salt/utils/platform.py @@ -187,9 +187,9 @@ def is_fedora(): """ Simple function to return if host is Fedora or not """ - (osname, osrelease, oscodename) = [ + (osname, osrelease, oscodename) = ( x.strip('"').strip("'") for x in linux_distribution() - ] + ) return osname == "Fedora" @@ -198,9 +198,9 @@ def is_photonos(): """ Simple function to return if host is Photon OS or not """ - (osname, osrelease, oscodename) = [ + (osname, osrelease, oscodename) = ( x.strip('"').strip("'") for x in linux_distribution() - ] + ) return osname == "VMware Photon OS" diff --git a/salt/utils/zeromq.py b/salt/utils/zeromq.py index 76814427d16..e44e373add4 100644 --- a/salt/utils/zeromq.py +++ b/salt/utils/zeromq.py @@ -21,10 +21,8 @@ LIBZMQ_VERSION_INFO = (-1, -1, -1) try: if zmq: - ZMQ_VERSION_INFO = tuple([int(v_el) for v_el in zmq.__version__.split(".")]) - LIBZMQ_VERSION_INFO = tuple( - [int(v_el) for v_el in zmq.zmq_version().split(".")] - ) + ZMQ_VERSION_INFO = tuple(int(v_el) for v_el in zmq.__version__.split(".")) + LIBZMQ_VERSION_INFO = tuple(int(v_el) for v_el in zmq.zmq_version().split(".")) except Exception: # pylint: disable=broad-except log.exception("Error while getting LibZMQ/PyZMQ library version") diff --git a/salt/version.py b/salt/version.py index 26dd224b094..9749ebe0c38 100644 --- a/salt/version.py +++ b/salt/version.py @@ -190,7 +190,7 @@ class SaltVersionsInfo(type): def versions(cls): if not cls._sorted_versions: cls._sorted_versions = sorted( - [getattr(cls, name) for name in dir(cls) if name.isupper()], + (getattr(cls, name) for name in dir(cls) if name.isupper()), key=operator.attrgetter("info"), ) return cls._sorted_versions diff --git a/tasks/docs.py b/tasks/docs.py index f8ee6a88494..22fe9a70c1b 100644 --- a/tasks/docs.py +++ b/tasks/docs.py @@ -401,7 +401,7 @@ def check_stray(ctx, files): DOCS_DIR / "ref" / "states" / "writing.rst", DOCS_DIR / "topics", ) - exclude_paths = tuple([str(p.relative_to(CODE_DIR)) for p in exclude_paths]) + exclude_paths = tuple(str(p.relative_to(CODE_DIR)) for p in exclude_paths) files = build_docs_paths(files) for path in files: if not str(path).startswith(str((DOCS_DIR / "ref").relative_to(CODE_DIR))): diff --git a/tests/integration/modules/test_git.py b/tests/integration/modules/test_git.py index 0fbcbcb5d3a..5b54e3b1803 100644 --- a/tests/integration/modules/test_git.py +++ b/tests/integration/modules/test_git.py @@ -157,7 +157,7 @@ class GitModuleTest(ModuleCase): ) ) ret = self.run_function("git.add", [self.repo, newdir]) - res = "\n".join(sorted(["add '{}'".format(x) for x in files_relpath])) + res = "\n".join(sorted("add '{}'".format(x) for x in files_relpath)) if salt.utils.platform.is_windows(): res = res.replace("\\", "/") self.assertEqual(ret, res) @@ -783,7 +783,7 @@ class GitModuleTest(ModuleCase): ) # Remove an entire dir expected = "\n".join( - sorted(["rm '" + os.path.join(entire_dir, x) + "'" for x in self.files]) + sorted("rm '" + os.path.join(entire_dir, x) + "'" for x in self.files) ) if salt.utils.platform.is_windows(): expected = expected.replace("\\", "/") diff --git a/tests/pytests/functional/modules/state/test_state.py b/tests/pytests/functional/modules/state/test_state.py index 0c8d5cbc86e..736e7ca2b3f 100644 --- a/tests/pytests/functional/modules/state/test_state.py +++ b/tests/pytests/functional/modules/state/test_state.py @@ -805,9 +805,9 @@ def test_parallel_state_with_long_tag(state, state_tree): __pub_jid="1", # Because these run in parallel we need a fake JID ) - comments = sorted([x.comment for x in ret]) + comments = sorted(x.comment for x in ret) expected = sorted( - ['Command "{}" run'.format(x) for x in (short_command, long_command)] + 'Command "{}" run'.format(x) for x in (short_command, long_command) ) assert comments == expected, "{} != {}".format(comments, expected) diff --git a/tests/pytests/integration/modules/test_rpmbuild_pkgbuild.py b/tests/pytests/integration/modules/test_rpmbuild_pkgbuild.py index 154d0641c47..cd40d7adc0a 100644 --- a/tests/pytests/integration/modules/test_rpmbuild_pkgbuild.py +++ b/tests/pytests/integration/modules/test_rpmbuild_pkgbuild.py @@ -271,7 +271,7 @@ def gpg_agent(request, gpghome): check=True, universal_newlines=True, ) - if tuple([int(p) for p in gpg_version_proc.stdout.split(".")]) >= (2, 1): + if tuple(int(p) for p in gpg_version_proc.stdout.split(".")) >= (2, 1): kill_option_supported = True else: kill_option_supported = False diff --git a/tests/pytests/unit/beacons/test_twilio_txt_msg.py b/tests/pytests/unit/beacons/test_twilio_txt_msg.py index e5bce4232be..b6976bb1445 100644 --- a/tests/pytests/unit/beacons/test_twilio_txt_msg.py +++ b/tests/pytests/unit/beacons/test_twilio_txt_msg.py @@ -13,7 +13,7 @@ try: import twilio # Grab version, ensure elements are ints - twilio_version = tuple([int(x) for x in twilio.__version_info__]) + twilio_version = tuple(int(x) for x in twilio.__version_info__) if twilio_version > (5,): TWILIO_5 = False else: diff --git a/tests/pytests/unit/states/test_host.py b/tests/pytests/unit/states/test_host.py index 2656e738fed..c374d8f966c 100644 --- a/tests/pytests/unit/states/test_host.py +++ b/tests/pytests/unit/states/test_host.py @@ -77,7 +77,7 @@ def test_present(): assert ret["changes"] == { "added": {ip_list[0]: [hostname], ip_list[1]: [hostname]} }, ret["changes"] - expected = sorted([call(x, hostname) for x in ip_list]) + expected = sorted(call(x, hostname) for x in ip_list) assert sorted(add_host.mock_calls) == expected, add_host.mock_calls assert rm_host.mock_calls == [], rm_host.mock_calls @@ -161,7 +161,7 @@ def test_present(): assert ret["changes"] == { "added": {ip_list[0]: [hostname], ip_list[1]: [hostname]}, }, ret["changes"] - expected = sorted([call(x, hostname) for x in ip_list]) + expected = sorted(call(x, hostname) for x in ip_list) assert sorted(add_host.mock_calls) == expected, add_host.mock_calls assert rm_host.mock_calls == [], rm_host.mock_calls @@ -185,7 +185,7 @@ def test_present(): "added": {ip_list[0]: [hostname], ip_list[1]: [hostname]}, "removed": {cur_ip: [hostname]}, }, ret["changes"] - expected = sorted([call(x, hostname) for x in ip_list]) + expected = sorted(call(x, hostname) for x in ip_list) assert sorted(add_host.mock_calls) == expected, add_host.mock_calls expected = [call(cur_ip, hostname)] assert rm_host.mock_calls == expected, rm_host.mock_calls @@ -331,10 +331,10 @@ def test_present(): "added": {ip_list[0]: [hostname], ip_list[1]: [hostname]}, "comment_added": {ip_list[0]: ["A comment"], ip_list[1]: ["A comment"]}, }, ret["changes"] - expected = sorted([call(x, hostname) for x in ip_list]) + expected = sorted(call(x, hostname) for x in ip_list) assert sorted(add_host_mock.mock_calls) == expected, add_host_mock.mock_calls - expected = sorted([call(x, "A comment") for x in ip_list]) + expected = sorted(call(x, "A comment") for x in ip_list) assert ( sorted(set_comment_mock.mock_calls) == expected ), set_comment_mock.mock_calls diff --git a/tests/pytests/unit/utils/jinja/test_custom_extensions.py b/tests/pytests/unit/utils/jinja/test_custom_extensions.py index c1c4451d83e..e1c62bd0076 100644 --- a/tests/pytests/unit/utils/jinja/test_custom_extensions.py +++ b/tests/pytests/unit/utils/jinja/test_custom_extensions.py @@ -458,7 +458,7 @@ def test_extend_dict_key_value(minion_opts, local_salt): # Test incorrect usage template = "{{ {} | extend_dict_key_value('bar:baz', 42) }}" - expected = r"Cannot extend {} with a {}.".format(type([]), type(42)) + expected = r"Cannot extend {} with a {}.".format(type([]), int) with pytest.raises(SaltRenderError, match=expected): render_jinja_tmpl( template, dict(opts=minion_opts, saltenv="test", salt=local_salt) diff --git a/tests/support/mock.py b/tests/support/mock.py index efeacc0a6b8..de46848a7fe 100644 --- a/tests/support/mock.py +++ b/tests/support/mock.py @@ -44,7 +44,7 @@ from mock import ( __mock_version = tuple( - [int(part) for part in mock.__version__.split(".") if part.isdigit()] + int(part) for part in mock.__version__.split(".") if part.isdigit() ) # pylint: disable=no-member if sys.version_info < (3, 6) and __mock_version < (2,): # We need mock >= 2.0.0 before Py3.6 diff --git a/tests/unit/fileserver/test_roots.py b/tests/unit/fileserver/test_roots.py index ab8605f318e..0b917091b46 100644 --- a/tests/unit/fileserver/test_roots.py +++ b/tests/unit/fileserver/test_roots.py @@ -231,12 +231,8 @@ class RootsTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModuleMockMix # between Python releases. lines_written = sorted(mtime_map_mock.write_calls()) expected = sorted( - [ - salt.utils.stringutils.to_bytes( - "{key}:{val}\n".format(key=key, val=val) - ) - for key, val in new_mtime_map.items() - ] + salt.utils.stringutils.to_bytes("{key}:{val}\n".format(key=key, val=val)) + for key, val in new_mtime_map.items() ) assert lines_written == expected, lines_written diff --git a/tests/unit/modules/test_twilio_notify.py b/tests/unit/modules/test_twilio_notify.py index 3528e04030d..1d0d4c0d44a 100644 --- a/tests/unit/modules/test_twilio_notify.py +++ b/tests/unit/modules/test_twilio_notify.py @@ -13,7 +13,7 @@ try: import twilio # Grab version, ensure elements are ints - twilio_version = tuple([int(x) for x in twilio.__version_info__]) + twilio_version = tuple(int(x) for x in twilio.__version_info__) if twilio_version > (5,): TWILIO_5 = False else: diff --git a/tests/unit/modules/test_zcbuildout.py b/tests/unit/modules/test_zcbuildout.py index e53efda9df4..9fab2a61789 100644 --- a/tests/unit/modules/test_zcbuildout.py +++ b/tests/unit/modules/test_zcbuildout.py @@ -287,7 +287,7 @@ class BuildoutTestCase(Base): @pytest.mark.slow_test def test__find_cfgs(self): result = sorted( - [a.replace(self.root, "") for a in buildout._find_cfgs(self.root)] + a.replace(self.root, "") for a in buildout._find_cfgs(self.root) ) assertlist = sorted( [ diff --git a/tests/unit/utils/test_data.py b/tests/unit/utils/test_data.py index 906955d6680..6d16e198999 100644 --- a/tests/unit/utils/test_data.py +++ b/tests/unit/utils/test_data.py @@ -771,11 +771,11 @@ class FilterFalseyTestCase(TestCase): self.assertIs(type(old_dict), type(new_dict)) # Test excluding int old_list = [0] - new_list = salt.utils.data.filter_falsey(old_list, ignore_types=[type(0)]) + new_list = salt.utils.data.filter_falsey(old_list, ignore_types=[int]) self.assertEqual(old_list, new_list) # Test excluding str (or unicode) (or both) old_list = [""] - new_list = salt.utils.data.filter_falsey(old_list, ignore_types=[type("")]) + new_list = salt.utils.data.filter_falsey(old_list, ignore_types=[str]) self.assertEqual(old_list, new_list) # Test excluding list old_list = [[]] @@ -987,7 +987,7 @@ class FilterFalseyTestCase(TestCase): [{"foo": ""}], ] new_list = salt.utils.data.filter_falsey( - old_list, recurse_depth=3, ignore_types=[type(0), type("")] + old_list, recurse_depth=3, ignore_types=[int, str] ) self.assertEqual( ["foo", ["foo"], ["foo"], {"foo": 0}, {"foo": "bar"}, [{"foo": ""}]], diff --git a/tests/unit/utils/test_thin.py b/tests/unit/utils/test_thin.py index 9a4c8a12751..fc5df09d8e6 100644 --- a/tests/unit/utils/test_thin.py +++ b/tests/unit/utils/test_thin.py @@ -223,7 +223,7 @@ class SSHThinTestCase(TestCase): with pytest.raises(salt.exceptions.SaltSystemExit): thin.get_ext_tops(cfg) assert len(thin.log.warning.mock_calls) == 4 - assert sorted([x[1][1] for x in thin.log.warning.mock_calls]) == [ + assert sorted(x[1][1] for x in thin.log.warning.mock_calls) == [ "jinja2", "msgpack", "tornado",