You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR runs [pyupgrade](https://github.com/asottile/pyupgrade) to modernize some syntax in the Python code base. (I am preparing a "better code" talk for our team that will reference this PR.)
The kinds of modernizing changes that pyupgrade makes are similar in purpose to those made by clang-tidy (#9860), but for Python. These include things like:
- Using literals for empty dicts `{}` and lists `[]`, because they are a bit faster and more readable than `dict()` or `list()`
- Removing extra parentheses or braces wrapping generator expressions if not needed
- Preferring format strings
- Using canonical error names, e.g. `IOError` became an alias for `OSError` in Python 3.3.
- Replacing the "new-style" class definitions like `class A(object):` with the simpler syntax `class A:`
- Removing unnecessary `__future__` imports that were needed for Python 2 compatibility, like `print_function` and `division`
- Using raw strings for regular expressions, to clarify intent and avoid extra escaping
The [pyupgrade README](https://github.com/asottile/pyupgrade) has a long showcase of other rules.
Notes for reviewers:
- pyupgrade has a lot of opinions on how to use type annotations, and I'm not sure if I like all of them (some may have compatibility issues?). I have skipped over the type annotations for now, to set a more reasonable scope for this PR. See commit 54b16b9 (since reverted) for examples. Please let me know what you think about these changes and I may investigate them further in a follow-up PR!
- I have not added this tool to our CI style checks via a pre-commit hook yet. That can be done in a follow-up PR if we agree that we would like these types of changes to be required in the future.
- I used the argument `--py37-plus` to only perform changes that are compatible with Python 3.7+.
- I can revert the changes to the vendored code in `versioneer.py` if desired. (It's pretty outdated anyway, it looks like we're using versioneer 0.18, released on January 1, 2017.)
Authors:
- Bradley Dice (https://github.com/bdice)
Approvers:
- Vyas Ramasubramani (https://github.com/vyasr)
- Charles Blackmon-Luca (https://github.com/charlesbluca)
- AJ Schmidt (https://github.com/ajschmidt8)
URL: #10141
0 commit comments