Skip to content
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

Apply assorted Pyugrade suggestions #4056

Merged
merged 5 commits into from
Nov 20, 2023

Conversation

DimitriPapadopoulos
Copy link
Contributor

Summary of changes

Apply some suggestions from pyupgrade.

Pull Request Checklist

@Avasam
Copy link
Contributor

Avasam commented Nov 17, 2023

Given that setuptools uses ruff, you could enforce and autofix this with https://docs.astral.sh/ruff/rules/#pyupgrade-up

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Nov 17, 2023

I have selected the pyupgrade suggestions that make most sense and are usually accepted in other projects. Would you agree to giving all pyupgrade suggestions a try, including redundant open modes?

Also, applying ruff-pyupgrade fixes now would be (partially?) redundant with your #4096.

Perhaps we can apply these two pull requests first, then set up ruff-pyupgrade and discuss any remaining rules to apply.

@Avasam
Copy link
Contributor

Avasam commented Nov 17, 2023

[...] including redundant open modes?

That one is often opinionated (and one of the best examples making Ruff's configurability better than pyupgrade directly, along with string formatting). So I'd leave that up to maintainers to decide.

Also, applying ruff-pyupgrade fixes now would be (partially?) redundant with your #4096.

#4096 does not aim at "upgrading code to newer syntax", just removing obsolete code paths/aliases and updating comments..

It's also never redundant to prevent code style/quality regressions imo. (that's what linters are for)

Perhaps we can apply these two pull requests first, then set up ruff-pyupgrade and discuss any remaining rules to apply.

My guess is that's probably what would be preferred.

@DimitriPapadopoulos
Copy link
Contributor Author

pyupgrade appears to be removing obsolete code paths too, at least partially.

In Python 3, io.open() is an alias for the builtin open() function.

https://docs.python.org/3/library/io.html#io.open

This is a suggestion from pyupgrade:
https://github.com/asottile/pyupgrade#open-alias
In Python ≥ 3.3, IOError is an alias of OSError.

https://docs.python.org/3/library/exceptions.html#IOError

This is a suggestion from pyupgrade:
https://github.com/asottile/pyupgrade#oserror-aliases
In Python ≥ 3.3, socket.error is an alias of OSError.

https://docs.python.org/3/library/socket.html#socket.error

This is a suggestion from pyupgrade:
https://github.com/asottile/pyupgrade#oserror-aliases
Starting with Python ≥ 3.8, lru_cache can be used as a straight
decorator with no arguments:

https://bugs.python.org/issue36772

This is a suggestion from pyupgrade:
https://github.com/asottile/pyupgrade#remove-parentheses-from-functoolslru_cache
@abravalheri
Copy link
Contributor

abravalheri commented Nov 20, 2023

Not sure why the diff-cover is failing... I thought it would just measure the difference between files. This PR is not making much of a difference regarding that...

I will try to re-run the failing CI, if it is only the diffcov test that is causing problems, I am inclined to merge this anyway...

@abravalheri abravalheri merged commit bbce801 into pypa:main Nov 20, 2023
22 of 23 checks passed
@abravalheri
Copy link
Contributor

abravalheri commented Nov 20, 2023

Thank you very much!

I agree that an approach for automatic corrections would be nice, but I also agree that we should incrementally build up to the point we can adopt it first.

@DimitriPapadopoulos DimitriPapadopoulos deleted the pyupgrade branch November 20, 2023 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants