Skip to content

Modernize Python syntax using pyupgrade --py36-plus #9342

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

Closed
wants to merge 2 commits into from
Closed

Modernize Python syntax using pyupgrade --py36-plus #9342

wants to merge 2 commits into from

Conversation

jdufresne
Copy link
Contributor

@jdufresne jdufresne commented Dec 23, 2020

  • Drop u-prefix from strings.
  • Remove __future__ imports.
  • Drop object in class definitions.
  • Replace codecs.open() and io.open() with builtin open(). In Python 3, these are equivalent.
  • Use shorter super().
  • Replace EnvironmentError and IOError with OSError. These were unified in Python 3.
  • Use yield from syntax.
  • Convert simple Python formatting to use f-strings.
  • Use updated updated TypedDict syntax.
  • Drop 'utf-8' as the argument to .encode()/.decode(). In Python 3, this is the default.

The src/pip/_vendor and tests/data directories were excluded.

pyupgrade is a tool to automatically upgrade syntax for newer versions of the language. For more details, see:
https://github.com/asottile/pyupgrade

@jdufresne
Copy link
Contributor Author

jdufresne commented Dec 23, 2020

I didn't add a news file as I feel this is already covered by:

https://github.com/pypa/pip/blob/1eebb12550cf4e207dc654b57553efe818792747/news/8802.removal.rst

But I can certainly add one if preferred.

@pradyunsg pradyunsg added the skip news Does not need a NEWS file entry (eg: trivial changes) label Dec 23, 2020
@uranusjr
Copy link
Member

Can this be done a few files at a time, or one feature at a time instead? Not all of the changes are straightforward (e.g. I would want to manually check encoding changes), but there’s no viable way to review this in one go.

@pradyunsg
Copy link
Member

A good way to split this would be how Black's ignore rules are set up in pre-commit's configuration.

pyupgrade is a tool to automatically upgrade syntax for newer versions
of the language. For more details, see:
https://github.com/asottile/pyupgrade

To keep the diff small, this change doesn't include Python 3.6+ syntax
features.

The `src/pip/_vendor` and `tests/data` directories were excluded.
- Drop object in class definitions.
- Replace `EnvironmentError` and `IOError` with `OSError`. These were
  unified in Python 3.
- Use `yield from` syntax.
- Convert simple Python formatting to use f-strings.
- Use updated updated `TypedDict` syntax.
- Drop 'utf-8' as the argument to `.encode()`/`.decode()`. In Python 3,
  this is the default.

The `src/pip/_vendor` and `tests/data` directories were excluded.

pyupgrade is a tool to automatically upgrade syntax for newer versions
of the language. For more details, see:
https://github.com/asottile/pyupgrade
@pradyunsg
Copy link
Member

I think a separate PR doing f-strings would clear up most/all of this diff?

@jdufresne
Copy link
Contributor Author

I think a separate PR doing f-strings would clear up most/all of this diff?

👍 Definitely. I'll close this and handle individual set of changes separately. F-strings handled in #9361

@jdufresne jdufresne closed this Dec 26, 2020
@uranusjr uranusjr mentioned this pull request Feb 10, 2021
@jdufresne jdufresne deleted the pyupgrade branch August 2, 2021 15:15
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip news Does not need a NEWS file entry (eg: trivial changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants