Skip to content

Replace sole use of maxdict by lru_cache. - #22323

Merged
timhoffm merged 2 commits into
matplotlib:mainfrom
anntzer:unmaxdict
Jan 27, 2022
Merged

timhoffm merged 2 commits into
matplotlib:mainfrom
anntzer:unmaxdict

Conversation

@anntzer

@anntzer anntzer commented Jan 26, 2022

Copy link
Copy Markdown
Contributor

... and expand the cache size, while we're at it.

Actual deprecation of maxdict can be done in #22299.

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@greglucas

Copy link
Copy Markdown
Contributor

:) You can bring the deprecation over here if you want, happy to close the other PR. While you're at it, do you want to add a test here to make sure we are hitting the cache as expected since I made the mistake on the other one that would only cache on each text instance?

@anntzer

anntzer commented Jan 26, 2022

Copy link
Copy Markdown
Contributor Author

Done (^2)

@greglucas greglucas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All failures appear to be CI related.

@@ -0,0 +1,4 @@
``matplotlib.cbook.maxdict`` is deprecated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change name of file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure

@greglucas greglucas mentioned this pull request Jan 26, 2022
1 of 6 tasks
@anntzer
anntzer force-pushed the unmaxdict branch 3 times, most recently from da764ff to 44d21ac Compare January 26, 2022 15:55
@anntzer

anntzer commented Jan 26, 2022

Copy link
Copy Markdown
Contributor Author

Edit: modified the implementation to not use pickle but instead key off an internally generated copy of fontprop (which the caller cannot access and thus cannot mutate).

@timhoffm timhoffm left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Modulo one comment improvement. May self-merge after adressing.

Ah, and rebase should fix the CI failure (#22326).

Comment thread lib/matplotlib/text.py Outdated
Comment on lines +96 to +97
# the passed-in argument do not mess up the cache. dpi is not used, but
# participates in cache invalidation (via the renderer).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# the passed-in argument do not mess up the cache. dpi is not used, but
# participates in cache invalidation (via the renderer).
# the passed-in argument do not mess up the cache.

Move that note down, because dpi is only passed on here. Clever tools will show unused in the function below and people might be tempted to remove it without consulting the context of the call site.

Comment thread lib/matplotlib/text.py Resolved
@tacaswell tacaswell added this to the v3.6.0 milestone Jan 26, 2022
Comment thread lib/matplotlib/tests/test_text.py Resolved
anntzer and others added 2 commits January 27, 2022 10:58
... and expand the cache size, while we're at it.
It was used in one place in the library and there is now
a standard library lru_cache that we can take advantage of instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants