Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 25be2f1

Browse files
committed
BLD: Make ft2font classes final
There appears to be no reason for them to be subtyped, as they are semi-private, and we don't do that.
1 parent aa70f69 commit 25be2f1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ft2font classes are now final
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The ft2font classes `.ft2font.FT2Font`, and `.ft2font.FT2Image` are now final
5+
and can no longer be subclassed.

lib/matplotlib/ft2font.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import BinaryIO, Literal, TypedDict, overload
1+
from typing import BinaryIO, Literal, TypedDict, final, overload
22

33
import numpy as np
44
from numpy.typing import NDArray
@@ -158,6 +158,7 @@ class _SfntPcltDict(TypedDict):
158158
widthType: int
159159
serifStyle: int
160160

161+
@final
161162
class FT2Font:
162163
ascender: int
163164
bbox: tuple[int, int, int, int]
@@ -233,11 +234,13 @@ class FT2Font:
233234
self, string: str, angle: float = ..., flags: int = ...
234235
) -> NDArray[np.float64]: ...
235236

237+
@final
236238
class FT2Image: # TODO: When updating mypy>=1.4, subclass from Buffer.
237239
def __init__(self, width: float, height: float) -> None: ...
238240
def draw_rect(self, x0: float, y0: float, x1: float, y1: float) -> None: ...
239241
def draw_rect_filled(self, x0: float, y0: float, x1: float, y1: float) -> None: ...
240242

243+
@final
241244
class Glyph:
242245
width: int
243246
height: int

src/ft2font_wrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static PyTypeObject* PyFT2Image_init_type()
146146
PyFT2ImageType.tp_name = "matplotlib.ft2font.FT2Image";
147147
PyFT2ImageType.tp_basicsize = sizeof(PyFT2Image);
148148
PyFT2ImageType.tp_dealloc = (destructor)PyFT2Image_dealloc;
149-
PyFT2ImageType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
149+
PyFT2ImageType.tp_flags = Py_TPFLAGS_DEFAULT;
150150
PyFT2ImageType.tp_methods = methods;
151151
PyFT2ImageType.tp_new = PyFT2Image_new;
152152
PyFT2ImageType.tp_init = (initproc)PyFT2Image_init;
@@ -236,7 +236,7 @@ static PyTypeObject *PyGlyph_init_type()
236236
PyGlyphType.tp_name = "matplotlib.ft2font.Glyph";
237237
PyGlyphType.tp_basicsize = sizeof(PyGlyph);
238238
PyGlyphType.tp_dealloc = (destructor)PyGlyph_dealloc;
239-
PyGlyphType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
239+
PyGlyphType.tp_flags = Py_TPFLAGS_DEFAULT;
240240
PyGlyphType.tp_members = members;
241241
PyGlyphType.tp_getset = getset;
242242

@@ -1495,7 +1495,7 @@ static PyTypeObject *PyFT2Font_init_type()
14951495
PyFT2FontType.tp_doc = PyFT2Font_init__doc__;
14961496
PyFT2FontType.tp_basicsize = sizeof(PyFT2Font);
14971497
PyFT2FontType.tp_dealloc = (destructor)PyFT2Font_dealloc;
1498-
PyFT2FontType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1498+
PyFT2FontType.tp_flags = Py_TPFLAGS_DEFAULT;
14991499
PyFT2FontType.tp_methods = methods;
15001500
PyFT2FontType.tp_getset = getset;
15011501
PyFT2FontType.tp_new = PyFT2Font_new;

0 commit comments

Comments
 (0)