Skip to content

Handle type mismatch on bit and register __eq__#5450

Merged
mergify[bot] merged 1 commit into
Qiskit:masterfrom
mtreinish:fix-attribute-error-in-register-eq
Nov 30, 2020
Merged

Handle type mismatch on bit and register __eq__#5450
mergify[bot] merged 1 commit into
Qiskit:masterfrom
mtreinish:fix-attribute-error-in-register-eq

Conversation

@mtreinish
Copy link
Copy Markdown
Member

@mtreinish mtreinish commented Nov 30, 2020

Summary

In #5272 the __eq__ method was changed to use a single string comparison
away from a nested attribute comparison for performance reasons. This
had the unexpected side effect that when comparing a register or a bit
object against an object of another type an AttributeError would be
raised because the private _repr attribute doesn't exist outside of
those classes. This leads to unexpected failures when running with aqua
because they were comparing a register to a string. This commit
addresses this by catching the attribute error and returning false
because objects of different types are not equal.

Details and comments

In Qiskit#5272 the __eq__ method was changed to use a single string comparison
away from a nested attribute comparison for performance reasons. This
had the unexpected side effect that when comparing a register or a bit
object against an object of another type an AttributeError would be
raised because the private _repr attribute doesn't exist outside of
those classes. This leads to unexpected failures when running with aqua
because they were comparing a register to a string. This commit
addresses this by catching the attribute error and returning false
because objects of different types are not equal.
@mtreinish mtreinish requested a review from a team as a code owner November 30, 2020 18:58
@kdk kdk added the automerge label Nov 30, 2020
@mergify mergify Bot merged commit 921b658 into Qiskit:master Nov 30, 2020
@mtreinish mtreinish deleted the fix-attribute-error-in-register-eq branch November 30, 2020 20:07
@kdk kdk added the Changelog: None Do not include in the GitHub Release changelog. label Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: None Do not include in the GitHub Release changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants