xen-bugtool/make_inventory(): Py3: Update tuple lambda to for loop #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update a
map()
inmake_inventory()
to also work with Python3 (using a for loop - more readable and concise):The syntax for
tuple
parameters inlambda
functions has been removed in Python3 and must be replaced:This code iterates over the inventory dictionary using the items() method and unpacks each key-value pair into k and v. Then, it calls the inventory_entry() function with the appropriate arguments.
In general, map() is useful when you want to apply a function to every item of an iterable and return a list of the results.
However, if you only need to iterate over the items of an iterable and perform some operation on each item, a for loop is often more readable and concise than using map().
Established for Python3 migration with a recent Python3 merge for xsconsole:
Replacing such map() loops with a for loop has already been established with the recently merged equivalent Python3 commit for xsconsole.
CI Tests of this code:
The functionality of this code is already tested by each of the test cases in tests/integration/ as all of them validate the contents and XML schema of bugtool-output/inventory.xml