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

really drop python<=3.7 #3391

Closed
wants to merge 3 commits into from
Closed

really drop python<=3.7 #3391

wants to merge 3 commits into from

Conversation

kloczek
Copy link

@kloczek kloczek commented Jun 6, 2024

Filter all code over pyupgrade --py38-plus.

Filter all code over `pyupgrade --py38-plus`.

Signed-off-by: Tomasz Kłoczko <[email protected]>
Mostly removes unused imports.

Signed-off-by: Tomasz Kłoczko <[email protected]>
@bdarnell
Copy link
Member

bdarnell commented Jun 6, 2024

Most of these actually date back to Python 3.0 or earlier (e.g. the default (object) base class was in 3.0, set literals in 2.7). I'm wary of change for the sake of change but it's probably time to change these and the tool helps make it safer. I've never liked the .format() method (introduced in 2.6), though - I prefer the % operator or f-strings. Looks like pyupgrade has an option to leave string formatting alone. (I wish it would let you run one rule at a time for ease of reviewing - get all of the (object) changes out of the way in one commit, etc)

I'm not sure about that second ruff commit - I think most if not all of those imports are needed for type checking. We already have flake8 that warns about unused imports so there shouldn't really be any.

@kloczek
Copy link
Author

kloczek commented Jun 6, 2024

flake8 is more and more behind of what ruff is able to detect.
Nevertheless with both commits test suite is OK (tornado.test.runtests) and pytest is failing the same way as without that those changes (as I've reported in #3390)

@bdarnell
Copy link
Member

bdarnell commented Jun 7, 2024

flake8 is more and more behind of what ruff is able to detect.

I'm not in the market for a new linter (well, I may switch from flake8 to plain pyflakes now that black and pep8 are diverging). I care more about a high signal-to-noise ratio than just detecting more stuff (this is why I use pyflakes and not pylint).

Nevertheless with both commits test suite is OK (tornado.test.runtests)

It also needs to pass the linters (tox -e lint. Also tox -e docs although i don't think that's going to be an issue here). The current failure just needs black to be run after pyupgrade, and then we'll see if mypy is happy with the ruff changes.

Signed-off-by: Tomasz Kłoczko <[email protected]>
@kloczek
Copy link
Author

kloczek commented Jun 8, 2024

OK I've added commit with all changes generated by black.

@@ -47,7 +47,7 @@
"foo".encode("idna")

# For undiagnosed reasons, 'latin1' codec may also need to be preloaded.
"foo".encode("latin1")
b"foo"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This useless-looking call to encode() is significant - it ensures that the codec is initialized here (where we are presumably executing on the main thread) instead of later in another thread, which has the potential to deadlock.

@bdarnell
Copy link
Member

I've got almost all the pyupgrade changes in a new PR, #3403. I had to hack on pyupgrade a bit to disable one change and then break things out into separate commits for easier review. I also found that running pyupgrade in two passes will convert percent formatting to str.format and then str.format to fstrings, which is nice.

@kloczek
Copy link
Author

kloczek commented Jun 26, 2024

Thank you 👍

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.

2 participants