-
Notifications
You must be signed in to change notification settings - Fork 36
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
Feature/pre commit pyupgrade #413
Conversation
bdf3b7a
to
38e7fd8
Compare
Codecov Report
@@ Coverage Diff @@
## master #413 +/- ##
==========================================
+ Coverage 76.41% 76.44% +0.03%
==========================================
Files 45 45
Lines 7139 7123 -16
==========================================
- Hits 5455 5445 -10
+ Misses 1684 1678 -6
Continue to review full report at Codecov.
|
What's the difference to a standard linter? It doesn't just point out the issue, but also fixes it? I know many projects that have pre-commit hooks that actually run some automated code improvement prior to the commit, it usually speeds up the workflow. |
@csadorf Good questions. Here’s the summary I am planning to give at dev meeting today: Yes, this hook modifies code (like black, unlike flake8). Pre-commit always runs on the git staging area but never modifies the staging area. All modifications by pre-commit hook(s) become unstaged changes, which can be added. This hook does not overlap with any other hook we currently use, as it is purely about modernization (its changes do not affect correctness). I believe all of the changes made the code simpler and more readable. As I have become more familiar with pre-commit and linters more generally, I now have a relatively strong preference for linters and analyzers that can fix things automatically, like black and this hook for pyupgrade. I find that writing code is much faster when I can just type the lines I want and not worry about the whitespace. Let a formatter (clang-format in C++, black or yapf in Python) handle the rest. Moreover, I think hooks that automatically apply their fixes can vastly speed up PR reviews and allow a greater focus on aspects like correctness, usability, and performance (because a high standard for code style is automatically enforced). |
Yes, I'm a strong proponent for auto-formatters. As long as they are only format changes and guaranteed not to alter the code semantics it saves lots of wasted review iterations and ensures high code quality. |
In dev meeting, we agreed that pyupgrade seems like a good tool and that we would also like to move towards adopting black in the future. |
@bdice one question? Did this all automatically got updated or did you have to do some sort of refactorings? |
@kidrahahjo All of the changes in this PR were performed by pyupgrade. I didn't have to do anything but |
(I accidentally closed this.) |
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.
Look's great
Description
I found a pre-commit hook called pyupgrade. It modernizes Python syntax. I configured it for 3.6+. I experimented with the tool and it seems to do a nice job, so I thought I would open a draft PR for discussion about whether this tool should be adopted. I reviewed its suggestions and all are valid.
Motivation and Context
Pro: Helps encourage good code style for the project.
Con: Another tool that could break.
Types of Changes
Checklist:
If necessary: