Skip to content

Use functools.cache instead of lru_cache to establish singletons. #29581

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

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/_fontconfig_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# there would have created cyclical dependency problems, because it also needs
# to be available from `matplotlib.rcsetup` (for parsing matplotlibrc files).

from functools import lru_cache, partial
from functools import cache, lru_cache, partial
import re

from pyparsing import (
Expand Down Expand Up @@ -52,7 +52,7 @@
}


@lru_cache # The parser instance is a singleton.
@cache # The parser instance is a singleton.
def _make_fontconfig_parser():
def comma_separated(elem):
return elem + ZeroOrMore(Suppress(",") + elem)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from collections import namedtuple
import enum
from functools import lru_cache, partial, wraps
from functools import cache, lru_cache, partial, wraps
import logging
import os
from pathlib import Path
Expand Down Expand Up @@ -1020,7 +1020,7 @@ def _parse_enc(path):


class _LuatexKpsewhich:
@lru_cache # A singleton.
@cache # A singleton.
def __new__(cls):
self = object.__new__(cls)
self._proc = self._new_proc()
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from base64 import b64encode
import copy
import dataclasses
from functools import lru_cache
from functools import cache, lru_cache
import functools
from io import BytesIO
import json
Expand Down Expand Up @@ -247,7 +247,7 @@ def _get_win32_installed_fonts():
return items


@lru_cache
@cache
def _get_fontconfig_fonts():
"""Cache and list the font paths known to ``fc-list``."""
try:
Expand All @@ -261,7 +261,7 @@ def _get_fontconfig_fonts():
return [Path(os.fsdecode(fname)) for fname in out.split(b'\n')]


@lru_cache
@cache
def _get_macos_fonts():
"""Cache and list the font paths known to ``system_profiler SPFontsDataType``."""
try:
Expand Down