-
Notifications
You must be signed in to change notification settings - Fork 125
Fix type comparisons to use isinstance
#430
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
base: master
Are you sure you want to change the base?
Conversation
Some of the code used `type(X) == Y` to compare types. Those constructs lead to warnings from `flake8`. It is better to use `isinstance`.
@@ -596,7 +596,7 @@ def representative_parameters(self) -> 'FermiHubbardParameters': | |||
def equals_for_rescaling(self, other: 'FermiHubbardParameters') -> bool: | |||
if not isinstance(other, FermiHubbardParameters): | |||
return False | |||
if type(self.layout) != type(other.layout): | |||
if not isinstance(self.layout, type(other.layout)): |
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.
Are we sure about this one? This has different behavior for subclasses of other.layout.
Same thing with several cases below as well.
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.
Looking at the code below, I think we can delete this if-block and update line 601 to
if isinstance(self.layout, ZigZagLayout) and isinstance(other.layout, ZigZagLayout):
Other updates below look OK to me.
@@ -601,7 +601,7 @@ def cnot_on_layer( | |||
cirq.Moment(cirq.CZ.on(qc, qt) for qc, qt in pairs_list), | |||
cirq.Moment(cirq.H.on_each(pair[1] for pair in pairs_list)), | |||
] | |||
elif type(depolarization_probability) == float: | |||
elif isinstance(depolarization_probability, float): |
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.
(optional) consider changing to numbers.Real
if we'd like to handle np.float32 values.
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.
Please address comments in recirq/fermi_hubbard/parameters.py before merging.
Some of the code used
type(X) == Y
to compare types. Those constructs lead to warnings fromflake8
because type comparisons should useisinstance
.