Fix triangles to avoid using is
to compare nodes
#7041
Merged
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.
Fixes #7038
Using
n is not node
compares whether n and node are the same object, not whether they are equal.Thanks to a bug report in #7038 we discovered that the string "46" can sometimes be created twice and not internedso that
n is not node
returns True even though both are equal to "46".The error occurs in
triangles
when ensuring that a node in not included in its list of neighbors (ruling out self-loops).n
is the neighbor in question andnode
is the node being checked. This only goes to prove that "46" is not always the same object as "46". They are the same object if they are interned.Unfortunately figuring out when interning occurs is quite complicated and it may change. So I could not think of a good test to write for this error. So, this PR just replaces the idiom
n is not node
withn != node
which is really how node comparisons should be written always.I don't think we usually do backports but if we release a 3.2.1 for any reason, we should include this fix. It does not occur in v3.1.