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

xen-bugtool/make_inventory(): Py3: Update tuple lambda to for loop #21

Conversation

bernhardkaindl
Copy link
Collaborator

@bernhardkaindl bernhardkaindl commented Nov 6, 2023

Update a map() in make_inventory() to also work with Python3 (using a for loop - more readable and concise):

The syntax for tuple parameters in lambda 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

Update this code to also work with Python3:

The syntax for tuple parameters in lambda 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().

Replacing such map() loops with a for loop has already been established
with the recently merged equivalent Python3 commit for xsconsole.

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

Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
@bernhardkaindl bernhardkaindl merged commit 529752b into xenserver:master Nov 8, 2023
2 checks passed
@bernhardkaindl bernhardkaindl deleted the private/bernhardk/py3-update-tuple-lambda-to-loop branch January 8, 2024 18:53
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.

3 participants