-
Notifications
You must be signed in to change notification settings - Fork 7.1k
update python syntax >=3.6 #4585
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
Hi @Borda! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
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.
Thanks for the RP @Borda ,
Overall I'm happy with the changes, we tend to favour f-string over formatted strings lately, and it's nice for everything to be consistent. The only issue is that it will add another "noisy" commit to git blame on github, but IMHO it's still worth it.
One thing I'm not sure about is the commit hook, considering that some of these changes are making torchscript unhappy (see comment below), we might not be able to enforce this with a hook.
Let's also ping @pmeier @fmassa @datumbox @prabhat00155 to see what they think.
torchvision/transforms/functional.py
Outdated
@@ -923,7 +921,7 @@ def _get_inverse_affine_matrix( | |||
# Thus, the inverse is M^-1 = C * RSS^-1 * C^-1 * T^-1 | |||
|
|||
rot = math.radians(angle) | |||
sx, sy = [math.radians(s) for s in shear] | |||
sx, sy = (math.radians(s) for s in shear) |
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.
Looks like torchscript in unhappy here, I think we should revert to a list
I was about to write something similar to Nicolas. I like the fact we modernize the code and think it's worth it. I wouldn't add it as a precommit for the reasons mentioned above. Not sure if we should try to split it in parts or do it all in one go. |
I think it's best to do it in one go to avoid too many noisy commits. As long as the tests are passing it should be OK. Hopefully we can trust |
I may have related thought as each statement (code line) can be written in many ways, is the actual optimal, personally, I would keep any of these hook/bots and try to rewrite some small number of lines to complain of hook and also to be fine with you and
I may add that these changes are one-time as it is applied codebase-wide... later it is the same as
if anything went wrong in future, you can just drop it 🐰 |
I might be missing something, but I don't think the changes here are related to For the rest, if there is a simple and easy way to make both the hook and torchscript happy, then we can consider the hook for inclusion, provided that it runs fast, etc. But |
not at all, I made it just as a parallel example, sorry for confusion
I will check it this week |
Thanks @Borda , Slightly related, I noticed that we started having string
I think they come from the recent black formatting.
We should try to fix those before applying |
@NicolasHug thay may be another step, so far you do not enforce much code formating, right?
this comes from placing a two-line string to a single line which would be otherwise caught sooner with any formatting tool like Black of YAPF... what do you think about adding any of them in future? |
We do enforce black-formatting now, since last week. But I think we should fix those |
do you have it also in pre-commit hooks? vision/.pre-commit-config.yaml Line 5 in 221dd5f
but I don't think that it is the optimal one, rather use - repo: https://github.com/psf/black
rev: 21.9b0
hooks:
- id: black
name: Format code I can add it in separate PR |
|
Ok with changing to use f-strings, although it's a pity that it will be a bit harder for git blame. But fine with me. |
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.
Thanks @Borda for the PR. Reference scripts are not tested by unit tests, did you verify that everything runs fine?
seems they require multi-node/GPU machines which I do not have in my disposal :( |
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.
Thanks for the PR @Borda ,
This LGTM with a minor comment below.
I checked the classification reference, it's working fine. The rest of the references should be OK as well - there's not torchscript stuff there anyway, and I think this is what was causing the few issues earlier.
I'm OK to keep the new hook for now as it runs pretty quickly. However if it starts getting in our way and forces us to fix things like in 418ad23, I think we will need to remove it.
Thanks!
@Borda Thanks a lot for the contribution. I believe this PR improves and modernizes the code-base. Though I understand that these changes came from I think it might be best to remove the hook from this PR and give us a bit more time to discuss whether we would like to revisit our past decision for automatic code modifications prior commit. This could happen on a separate PR that would be easier to invert if need be. Let me know what you think? |
resolved conflicts and commented out the hook so later you can just uncomment it back... |
seems to be failing on Segmentation fault :/ |
@Borda It's not your PR, our CI is toasted... It should be resolved tomorrow using the latest nightly of PyTorch. Apologies for the inconvenience. |
@datumbox fixed and resolved conflicts... |
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.
I went through the entire PR quickly. Unfortunately this is very hard because of the volume of files involved. I think overall looks OK, the if/elif marked above seemed to appear only to a couple of places so perhaps it was not reverted everywhere originally.
The changes on the code are for the best; I agree it produced a much cleaner result. I did find a couple of issues with the fstrings though (see below), which might be indicating issues with the automated tool used to refactor the code. Let me know your thoughts.
@datumbox thank you for your review, I have fixed all issues... |
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.
Thanks for the changes!
@Borda thanks a lot for the PR and for bearing with us. There are still some minor cases where the script didn't use No need to do anything more on your end :) Thanks a lot! |
Thank you! |
Hey @NicolasHug! You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py |
…ing pyupgrade (#4585) Summary: Co-authored-by: Nicolas Hug <[email protected]> Reviewed By: datumbox Differential Revision: D32064703 fbshipit-source-id: 5d8a0823844ec36e82d94cddaf5dd25ac18327f3
…rade (pytorch#4585) Co-authored-by: Nicolas Hug <[email protected]>
In fact, I was just adding a new hook to pre-commit
pyupgrade
which generated all these changesalso I have added
python_requires=">=3.6",
to the seup.pyAn alternative would be enable pre-commit bot and then it would be clear that most of the changes comes just from the pre-commit hooks, see https://pre-commit.ci/