bpo-31417 Use the enumerate function where appropriate.#3497
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
vstinner
left a comment
There was a problem hiding this comment.
LGTM, except of a minor comment.
| @@ -554,9 +554,9 @@ def replace_paths_in_code(self, co): | |||
| self.processed_paths.append(original_filename) | |||
|
|
|||
| consts = list(co.co_consts) | |||
There was a problem hiding this comment.
While we modify this function, I suggest to move type(co) out of the loop:
code_type = type(co)
| build = {} | ||
| for i in range(len(sources)): | ||
| src = sources[i] | ||
| for i, src in enumerate(sources): |
There was a problem hiding this comment.
This stell leaves the obj = objects[i], why not just for src, obj in zip(sources, objects):
There was a problem hiding this comment.
I tried to stay close to the original code and do what was needed to replace range(len(sources)) with enumerate(sources).
Your suggestion could be done but it looks like the comments in the bug tracker would prefer no changes at all.
| specs = [] | ||
| for i in range(len(args)): | ||
| specs.append(convert(args[i])) | ||
| for i, arg in enumerate(args): |
There was a problem hiding this comment.
Is there a reason to keep the i at all here?
There was a problem hiding this comment.
This pattern can be seen in places in the repository.
For example, there is a similar pattern in the inspect.py module in the Signature class:
for idx, param in enumerate(parameters):
where idx is not subsequently used.
The original code also did not use a standard:
for i in args:
I focused on replacing range(len(args)) with enumerate(args).
To make code explicit and more readable
Use the enumerate function to replace occurrences of the pattern:
for i in range(len(sources)): src = sources[i]https://bugs.python.org/issue31417
https://bugs.python.org/issue31417