Change from float to numbers.Real where appropriate#445
Change from float to numbers.Real where appropriate#445RahilJain1366 wants to merge 6 commits intoquantumlib:mainfrom
float to numbers.Real where appropriate#445Conversation
This replaces the `Real as NumbersReal` import and the `RealNumber = Union[int, float]` alias with direct usage of `numbers.Real`.
float to numbers.Real where appropriate
|
@RahilJain1366 Thanks for this work. I finally looked at it, and it seemed like some of the things like the |
|
@dstrain115 I think someone other than me should review the final version of this PR; would you be willing? |
|
Hi @mhucka, thanks for taking the time to review and push the updates! I should have kept it as Real instead of naming NumbersReal, it looks cleaner. |
|
Was there a reason behind doing this change? While numbers.Real is more general, isinstance checks for numbers.Real is slower and it can sometimes cause more problems for callers of the function, since they need to deal with a more general return type. Since this is in ReCirq, it's probably fine, since this code is not likely used outside the library itself. I am just wondering as to the motivation for this. |
A very excellent question! This PR is in response to issue #435, which itself came in response to discussions on PR #430. The latter PR addressed some flake8 warnings about That's a good point about the implication of return types. Should this PR be changed to avoid returning |
|
Yeah, I think I would be more comfortable with removing the return type changes. I think it's better practice if we change inputs to be as general as possible but keep outputs specific as possible. This makes the functions most flexible to use. Otherwise, (soft) LGTM |
Hi @mhucka
I found instance(..., float) in all the files committed in the PR. I changed it to numbers.real. Is there anything else which I would need to change on this? I was able to see these files broadly over the codebase.
Could please review and let me know if any further changes are required. I had run pytest for each individual .py file and it was successful.
Thanks,
Rahil Jain