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

Conversation

bhipple
Copy link
Contributor

@bhipple bhipple commented Mar 22, 2020

In py2, map returned a list; in py3, it returns an iterator, which can't be indexed.

Per upstream guidelines [1], while it is possible to just add a list() cast,
it's more idiomatic to use a list comprehension for mapping. This is more
pythonic regardless, and still py2 compatible.

Partial progress towards #29

CC @grahamc @AmineChikhaoui

[1] https://docs.python.org/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists

In py2, map returned a list; in py3, it returns an iterator, which can't be indexed.

Per upstream guidelines [1], while it is possible to just add a list() cast,
it's more idiomatic to use a list comprehension for mapping. This is more
pythonic regardless, and still py2 compatible.

Partial progress towards NixOS#29

CC @grahamc @AmineChikhaoui

[1] https://docs.python.org/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists
Copy link
Contributor Author

@bhipple bhipple left a comment

Choose a reason for hiding this comment

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

Tested with a local build and re-deploy of my AWS cluster, seems to be working fine.

@@ -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.

@grahamc grahamc merged commit 3cf582f into NixOS:master Mar 22, 2020
@bhipple bhipple deleted the py3/map branch March 22, 2020 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants