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

use enumerate where applicable fixing _generate_multi_deps_list #4720

Open
wants to merge 2 commits into
base: 5.0.x
Choose a base branch
from

Conversation

Flamefire
Copy link
Contributor

PyLint found uses of range(len(...)) where the index was then used to access an element.

Using enumerate yields the value together with the index making the intention clearer (and the code likely faster).

This also led to a nice simplification possibility in make_module_dep, get_parsed_multi_deps and configobj.walk and a possible bugfix in _generate_multi_deps_list:

The code generating the load statement uses the first module of each name in self.app.cfg.multi_deps but the code generating the help text has an additional version check. We don't need that and it can possibly be wrong if the order of the versions was different somehow.
I simply collect all modules with the given name using a (fast) list comprehension and mark the first as the default

The multi-dep module loaded by default is the first entry in
`self-cfg-multi_deps` for each name.
Using the version order from the easyconfig could lead to
inconsistencies between description and behavior.
In some places we require the index and value of a list and using
`range(len(...))` is not optimal for that.
Using `enumerate` yields the value together with the index making the
intention clearer (and the code likely faster).
@boegel boegel added this to the release after 4.9.4 milestone Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants