Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py3-prep: fix map with list comprehensions #35

Merged
merged 1 commit into from Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions nixopsaws/backends/ec2.py
Expand Up @@ -862,12 +862,10 @@ def security_groups_to_ids(self, subnetId, groups):
if sg_names != [] and subnetId != "":
self.connect_vpc()
vpc_id = self._conn_vpc.get_all_subnets([subnetId])[0].vpc_id
groups = map(
lambda g: nixopsaws.ec2_utils.name_to_security_group(
self._conn, g, vpc_id
),
groups,
)
groups = [
nixopsaws.ec2_utils.name_to_security_group(self._conn, g, vpc_id)
for g in groups
]

return groups

Expand Down
12 changes: 6 additions & 6 deletions nixopsaws/resources/cloudwatch_metric_alarm.py
Expand Up @@ -127,7 +127,7 @@ def resolve_values(kv):

return kv

cfg["Dimensions"] = map(resolve_values, defn.dimensions)
cfg["Dimensions"] = [resolve_values(v) for v in defn.dimensions]

def resolve_action(a):
if a.startswith("res-"):
Expand All @@ -142,11 +142,11 @@ def resolve_action(a):
return a

# resolve sns topics
cfg["AlarmActions"] = map(resolve_action, defn.alarm_actions)
cfg["OKActions"] = map(resolve_action, defn.ok_actions)
cfg["InsufficientDataActions"] = map(
resolve_action, defn.insufficient_data_actions
)
cfg["AlarmActions"] = [resolve_action(a) for a in defn.alarm_actions]
cfg["OKActions"] = [resolve_action(a) for a in defn.ok_actions]
cfg["InsufficientDataActions"] = [
resolve_action(a) for a in defn.insufficient_data_actions
]

if self.put_config != cfg or check:
client.put_metric_alarm(**cfg)
Expand Down
8 changes: 4 additions & 4 deletions nixopsaws/resources/elastic_file_system_mount_target.py
Expand Up @@ -208,9 +208,9 @@ def security_groups_to_ids(self, region, access_key_id, subnetId, groups):
sg_names = filter(lambda g: not g.startswith("sg-"), groups)
if sg_names != [] and subnetId != "":
vpc_id = conn_vpc.get_all_subnets([subnetId])[0].vpc_id
groups = map(
lambda g: nixopsaws.ec2_utils.name_to_security_group(conn, g, vpc_id),
groups,
)
groups = [
nixopsaws.ec2_utils.name_to_security_group(conn, g, vpc_id)
for g in groups
]

return groups
6 changes: 3 additions & 3 deletions nixopsaws/resources/route53_health_check.py
Expand Up @@ -134,9 +134,9 @@ def resolve_machine_ip(v):
}

if defn.type == "CALCULATED":
cfg["ChildHealthChecks"] = map(
self.resolve_health_check, defn.child_health_checks
)
cfg["ChildHealthChecks"] = [
self.resolve_health_check(c) for c in defn.child_health_checks
]
cfg["HealthThreshold"] = defn.health_threshold
else:
cfg["RequestInterval"] = defn.request_interval
Expand Down
3 changes: 2 additions & 1 deletion nixopsaws/resources/route53_hosted_zone.py
Expand Up @@ -31,7 +31,8 @@ def __init__(self, xml, config):
self.private_zone = config["privateZone"]
self.zone_name = config["name"]
self.associated_vpcs = config["associatedVPCs"]
map(lambda x: x.pop("_module"), self.associated_vpcs)
for vpc in self.associated_vpcs:
vpc.pop("_module")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the "tricky case" mentioned in https://docs.python.org/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists where we don't actually care about the list coming back. Implemented the swap to a for loop, as upstream recommends.



class Route53HostedZoneState(nixops.resources.ResourceState):
Expand Down
6 changes: 2 additions & 4 deletions nixopsaws/resources/route53_recordset.py
Expand Up @@ -221,7 +221,7 @@ def resolve_machine_ip(v):
else:
return v

defn.record_values = map(resolve_machine_ip, defn.record_values)
defn.record_values = [resolve_machine_ip(m) for m in defn.record_values]

changed = (
self.record_values != defn.record_values
Expand Down Expand Up @@ -268,9 +268,7 @@ def make_batch(self, action, obj):
"Name": obj.domain_name,
"Type": obj.record_type,
"TTL": int(obj.ttl),
"ResourceRecords": map(
lambda rv: {"Value": rv}, obj.record_values
),
"ResourceRecords": [{"Value": rv} for rv in obj.record_values],
},
},
]
Expand Down