-
Notifications
You must be signed in to change notification settings - Fork 16.5k
chore(pre-commit): Add pyupgrade and pycln hooks #24197
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
chore(pre-commit): Add pyupgrade and pycln hooks #24197
Conversation
3573145 to
e92b2d3
Compare
superset/views/core.py
Outdated
Check warning
Code scanning / CodeQL
URL redirection from remote source
2328dc8 to
e92b2d3
Compare
.pre-commit-config.yaml
Outdated
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.
pyupgrade may perform type rewrites, etc. rendering some imports obsolete. It seemed prudent to also include a hook which then cleans up unused imports.
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.
Does pyupgrade is restrained to our supported Python versions? Another way of asking is if a new Python version is launched with a new syntax, will pyupgrade try to change the files to the new syntax before we support this new version?
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.
@michael-s-molina yes. Per the --py39-plus CLI argument it ensures that the changes are compatible with Python versions >= 3.9 which is the minimum version we currently support.
Codecov Report
@@ Coverage Diff @@
## master #24197 +/- ##
=======================================
Coverage 68.31% 68.31%
=======================================
Files 1957 1957
Lines 75597 75621 +24
Branches 8222 8222
=======================================
+ Hits 51641 51661 +20
- Misses 21848 21852 +4
Partials 2108 2108
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 11 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
e92b2d3 to
2af3468
Compare
.pre-commit-config.yaml
Outdated
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.
pycln chokes on module not found errors when we try importing the default configs.
cfab874 to
8952492
Compare
superset/connectors/base/models.py
Outdated
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.
b8b64fa to
9e99d8c
Compare
michael-s-molina
left a comment
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.
LGTM. Thank you very much for this improvement @john-bodley! It will contribute a lot to code standardization.
Reviewing this PR made me aware of how much untyped structures (dict) we have in the codebase and the consequences of that in terms of bugs and duplicated logic 😟
I'm also going to ping @villebro @eschutho @jfrag1 in case they have extensions that may be affected by this PR.
superset/connectors/sqla/models.py
Outdated
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.
It's way more readable then the Optional version 😄
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.
Yup. The term Optional is such a misnomer and a bad choice to represent something that could be None. The PEP-604 typing rewrites currently only apply to those files which contain the following,
from __future__ import annotations
though will become ubiquitous after we drop support for Python 3.9.
9e99d8c to
b1cda7c
Compare
SUMMARY
I thought there was merit in "keeping up with the Joneses" in terms of ensuring our Python code is inline with the evolution of the language.
pyupgrade is a tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language. This PR adds said pre-commit hook (in addition to
pyclnwhich removes unused imports) to help ensure your code style format is fresh.Apologies for the scale of the change. I wasn't able to find any setting in
pyupgradeto make this more digestible, unless we opted to incrementally set the minimum Python requirement.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
CI.
ADDITIONAL INFORMATION