1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Switch from map and filter to list comprehensions and generator expressions (#27198)

One of the complex map + filter + lambda combinations here was causing
pylint to have a rare false positive detecting undefined variables.

Switch to list comprehensions and generator expressions which are
easi(er) to read for humans and do not confuse pylint.

References #27193
This commit is contained in:
Toshio Kuratomi 2017-07-22 19:12:35 -07:00 committed by GitHub
parent 1c40631382
commit 4e8b28e404

View file

@ -226,18 +226,18 @@ class GalaxyCLI(CLI):
skeleton_ignore_expressions = ['^.*/.git_keep$']
role_skeleton = os.path.expanduser(role_skeleton)
skeleton_ignore_re = list(map(lambda x: re.compile(x), skeleton_ignore_expressions))
skeleton_ignore_re = [re.compile(x) for x in skeleton_ignore_expressions]
template_env = Environment(loader=FileSystemLoader(role_skeleton))
for root, dirs, files in os.walk(role_skeleton, topdown=True):
rel_root = os.path.relpath(root, role_skeleton)
in_templates_dir = rel_root.split(os.sep, 1)[0] == 'templates'
dirs[:] = filter(lambda d: not any(map(lambda r: r.match(os.path.join(rel_root, d)), skeleton_ignore_re)), dirs)
dirs[:] = [d for d in dirs if not any(r.match(os.path.join(rel_root, d)) for r in skeleton_ignore_re)]
for f in files:
filename, ext = os.path.splitext(f)
if any(map(lambda r: r.match(os.path.join(rel_root, f)), skeleton_ignore_re)):
if any(r.match(os.path.join(rel_root, f)) for r in skeleton_ignore_re):
continue
elif ext == ".j2" and not in_templates_dir:
src_template = os.path.join(rel_root, f)
@ -343,8 +343,7 @@ class GalaxyCLI(CLI):
try:
roles_left += [
GalaxyRole(self.galaxy, **r) for r in
map(RoleRequirement.role_yaml_parse,
yaml.safe_load(f_include))
(RoleRequirement.role_yaml_parse(i) for i in yaml.safe_load(f_include))
]
except Exception as e:
msg = "Unable to load data from the include requirements file: %s %s"