Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python 3.9 upgrade#24980

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ksunden merged 3 commits intomatplotlib:mainfromgreglucas:py39-upgrade
Jan 21, 2023
Merged

Python 3.9 upgrade#24980

ksunden merged 3 commits intomatplotlib:mainfromgreglucas:py39-upgrade
Jan 21, 2023

Conversation

greglucas
Copy link
Contributor

PR Summary

Now that we are on Python 3.9+ (#24919), we can update/simplify some of the code.

Automated command line utility for it:

pyupgrade --py39-plus `find . -name "*.py" -type f`

A lot of this is f-string updates, so I added the first commit to the git ignore blame so there is less churn in the blame lookups.
There are also some OSError aliases and getting rid of the unnecessary parentheses in thelru_cache decorator

PR Checklist

Documentation and Tests

  • [N/A] Has pytest style unit tests (andpytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • [N/A] API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • [N/A] Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

@greglucas
Copy link
ContributorAuthor

pre-commit.ci autofix

pre-commit-ci[bot] reacted with rocket emoji

"/{name}{{{bbox} sc\n".format(
name=font.get_glyph_name(glyph_id),
bbox=" ".join(map(str, [g.horiAdvance, 0, *g.bbox])),
)
Copy link
Member

Choose a reason for hiding this comment

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

Ithink that one can get f-strings here as well (although those will be horrible...) if it is executed again?

@oscargus
Copy link
Member

oscargus commentedJan 14, 2023
edited
Loading

In general, I'm tempting to skip the f-string conversion and let it evolve "organically" as some of them are quite painful as@ksunden points out (others are obviously a clear improvement). Also, some that are turned into format should probably be f-strings (others not).

(Interesting that some unpacking comprehensions are converted into tuples, but not things likeif a in ["b", "c"]:.)

Edit: to be clear, things that are not f-string conversions, I do not object to.

@@ -231,7 +231,7 @@ def _check_versions():

# The decorator ensures this always returns the same handler (and it is only
# attached once).
@functools.lru_cache()
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these should be converted to functions.cache for clarity, in fact.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I updated some of them where I thought an unbounded cache was alright, but others I figured we can handle later if we want to change to unbounded rather than the default size of 128. When I was looking through thelru_cache locations it looked like we may even have some decorated instance methods with self that may be keeping instances alive, I wonder if that is causing any of the slowly growing memory leaks that have been reported...

Copy link
Contributor

Choose a reason for hiding this comment

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

I was specifically referring to cases where the cache just serves to establish a singleton, like here.

@greglucas
Copy link
ContributorAuthor

I went through every.format() call and subjectively evaluated whether f-strings would be nicer or not. So, this is definitely most of the locations that can/should be updated now (even more than the automatic formatter picked up the first go-around). I personally prefer to just get formatting changes updated in one go so you can ignore that commit more easily through blames.

@greglucasgreglucasforce-pushed thepy39-upgrade branch 2 times, most recently from89c996d to5c9d97eCompareJanuary 17, 2023 04:44
@timhoffm
Copy link
Member

I think it would be a good idea to add a.git-blame-ignore-revs file. See alsohttps://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/

@greglucas
Copy link
ContributorAuthor

I think it would be a good idea to add a .git-blame-ignore-revs file. See alsohttps://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/

Yes, I agree and we already have one that I updated here :)
https://github.com/matplotlib/matplotlib/pull/24980/files#diff-f247fbfbe928b907db42554d0b3006b28dd11c25a59be031abda73b11a2c934a

timhoffm reacted with thumbs up emoji

ksunden
ksunden previously approved these changesJan 19, 2023
@ksundenksunden added this to thev3.8.0 milestoneJan 19, 2023
Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

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

This is good; I can drop my f-string stash now.

@greglucas
Copy link
ContributorAuthor

Thanks,@QuLogic, good recommendations as usual!

@ksundenksunden dismissed theirstale reviewJanuary 20, 2023 18:06

conversations in setup.py comments

Command: `pyupgrade --py39-plus`Manual updates to add some f-strings and ignore f-strings in texformats.
@ksundenksunden merged commit6a9a071 intomatplotlib:mainJan 21, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@anntzeranntzeranntzer left review comments

@ksundenksundenksunden left review comments

@oscargusoscargusoscargus left review comments

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.8.0
Development

Successfully merging this pull request may close these issues.

6 participants
@greglucas@oscargus@timhoffm@QuLogic@anntzer@ksunden

[8]ページ先頭

©2009-2025 Movatter.jp