-
Notifications
You must be signed in to change notification settings - Fork 125
Change 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
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`.
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.
Good idea. Since there may be other places in the code where a similar change ought to be made, I won't do it in this PR, and instead I opened an issue (#435) to remind us to do a broader check for numerical type comparisons that might not behave as expected with NumPy 2.
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.
Per [comments by @pavoljuhas in review](quantumlib#430 (comment)), this rewrites a couple of lines to simplify a comparisons.
isinstance
isinstance
isinstance
isinstance
Some of the code used
type(X) == Y
to compare types. Those constructs lead to warnings fromflake8
because type comparisons should useisinstance
.