-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Pylint: enable modified-iterating-list and bugfix #10338
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 5371321815
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Might prevent a bug in the future.
if self.template_dag_dep.direct_successors(node_id_t): | ||
maximal_index = self.template_dag_dep.direct_successors(node_id_t)[-1] | ||
for elem in pred: | ||
for elem in matches: | ||
if elem > maximal_index: | ||
pred.remove(elem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me that this is correct, because in the lines just out of sight of this diff, pred
is modified such that it's no longer the same as matches
. This change could cause an IndexError
to be emitted if node_id_t
ends up greater than maximal_index
(though I don't know if that's possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. I read the lines above, but somehow forgot that remove
will throw an error if the value is not present. Even if this works because of the nature of the data, I'd say it's too opaque and fragile to write it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as this code is being touched, it might be a good idea to rewrite it a bit. Maybe this:
matches = [_match[0] for _match in self.match]
pred = matches.copy()
pred.sort()
if direct_successors := self.template_dag_dep.direct_successors(node_id_t):
maximal_index = direct_successors[-1]
pred = [_match for _match in matches if _match <= maximal_index]
else:
pred = matches.copy()
if node_id_t in pred:
pred.remove(node_id_t)
i think this was resolved in #12294. sorry to step on toes, but i think this can be closed! |
Joe: thanks for helping tidy the old PRs up! Lev won't mind that this minor PR staled and got obsoleted (but I think he's a bit busy at the moment) - thanks for fixing it elsewhere. |
Turned on the
modified-iterating-list
pylint check and used it to find a bug.The iteration would fail to remove matching list elements if they along came two-in-a-row.
Here's a simplified illustration of the problematic idiom:
Notice that
13
makes it through despite the filter.For this PR I put a minimal change to fix the issue, but the rest of that routine does smell a bit funny to me and it would likely benefit from a rewrite. Eg, I'm not sure what was the intention with the superfluous conditional here:
Anyway, this all relates to #9614