From a695e93bf050cc09dfceab541b980bfa76f06b62 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 19 Jul 2020 17:46:22 +0200 Subject: [PATCH] Deprecate the unneeded Fonts.destroy. Neither `used_characters` nor `glyphd` cause circular references, so we can let the normal refcount collector handle the destruction. --- doc/api/next_api_changes/deprecations/18003-AL.rst | 3 +++ lib/matplotlib/mathtext.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 doc/api/next_api_changes/deprecations/18003-AL.rst diff --git a/doc/api/next_api_changes/deprecations/18003-AL.rst b/doc/api/next_api_changes/deprecations/18003-AL.rst new file mode 100644 index 000000000000..c5c941e784ca --- /dev/null +++ b/doc/api/next_api_changes/deprecations/18003-AL.rst @@ -0,0 +1,3 @@ +mathtext.Fonts.destroy +~~~~~~~~~~~~~~~~~~~~~~ +... is deprecated, because Fonts do not create reference loops anyways. diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index fe7138fedec0..8df1038421ba 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -398,6 +398,7 @@ def __init__(self, default_font_prop, mathtext_backend): self.mathtext_backend = mathtext_backend self.used_characters = {} + @cbook.deprecated("3.4") def destroy(self): """ Fix any cyclical references before the object is about @@ -519,7 +520,11 @@ def get_results(self, box): """ result = self.mathtext_backend.get_results( box, self.get_used_characters()) - self.destroy() + if self.destroy != TruetypeFonts.destroy.__get__(self): + destroy = cbook._deprecate_method_override( + __class__.destroy, self, since="3.4") + if destroy: + destroy() return result def get_sized_alternatives_for_symbol(self, fontname, sym): @@ -547,6 +552,7 @@ def __init__(self, default_font_prop, mathtext_backend): self._fonts['default'] = default_font self._fonts['regular'] = default_font + @cbook.deprecated("3.4") def destroy(self): self.glyphd = None Fonts.destroy(self)