Skip to content

Commit b40c001

Browse files
committed
Adjust _imagingft.pyi to match reality
1 parent 5a7fc6c commit b40c001

3 files changed

Lines changed: 27 additions & 29 deletions

File tree

Tests/test_font_pcf_charsets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ def test_textsize(
9797
tempname = save_font(request, tmp_path, encoding)
9898
font = ImageFont.load(tempname)
9999
for i in range(255):
100-
ox, oy, dx, dy = font.getbbox(bytearray([i]))
100+
ox, oy, dx, dy = font.getbbox(bytes([i]))
101101
assert ox == 0
102102
assert oy == 0
103103
assert dy == 20
104104
assert dx in (0, 10)
105-
assert font.getlength(bytearray([i])) == dx
105+
assert font.getlength(bytes([i])) == dx
106106
message = charsets[encoding]["message"].encode(encoding)
107107
for i in range(len(message)):
108108
msg = message[: i + 1]

src/PIL/ImageFont.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Layout(IntEnum):
7474
core = DeferredError.new(ex)
7575

7676

77-
def _string_length_check(text: str | bytes | bytearray) -> None:
77+
def _string_length_check(text: str | bytes) -> None:
7878
if MAX_STRING_LENGTH is not None and len(text) > MAX_STRING_LENGTH:
7979
msg = "too many characters in string"
8080
raise ValueError(msg)
@@ -101,7 +101,7 @@ class BaseImageFont(abc.ABC):
101101

102102
@abc.abstractmethod
103103
def getbbox(
104-
self, text: str | bytes | bytearray, *args: Any, **kwargs: Any
104+
self, text: str | bytes, *args: Any, **kwargs: Any
105105
) -> tuple[float, float, float, float]:
106106
pass
107107

@@ -206,7 +206,7 @@ def getmask(
206206
return self.font.getmask(text, mode)
207207

208208
def getbbox(
209-
self, text: str | bytes | bytearray, *args: Any, **kwargs: Any
209+
self, text: str | bytes, *args: Any, **kwargs: Any
210210
) -> tuple[int, int, int, int]:
211211
"""
212212
Returns bounding box (in pixels) of given text.
@@ -221,9 +221,7 @@ def getbbox(
221221
width, height = self.font.getsize(text)
222222
return 0, 0, width, height
223223

224-
def getlength(
225-
self, text: str | bytes | bytearray, *args: Any, **kwargs: Any
226-
) -> int:
224+
def getlength(self, text: str | bytes, *args: Any, **kwargs: Any) -> int:
227225
"""
228226
Returns length (in pixels) of given text.
229227
This is the amount by which following text should be offset.
@@ -406,7 +404,7 @@ def getlength(
406404

407405
def getbbox(
408406
self,
409-
text: str | bytes | bytearray,
407+
text: str | bytes,
410408
mode: str = "",
411409
direction: str | None = None,
412410
features: list[str] | None = None,
@@ -774,7 +772,7 @@ def getmask(
774772
return im
775773

776774
def getbbox(
777-
self, text: str | bytes | bytearray, *args: Any, **kwargs: Any
775+
self, text: str | bytes, *args: Any, **kwargs: Any
778776
) -> tuple[int, int, float, float]:
779777
# TransposedFont doesn't support getmask2, move top-left point to (0, 0)
780778
# this has no effect on ImageFont and simulates anchor="lt" for FreeTypeFont

src/PIL/_imagingft.pyi

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@ class Font:
2424
self,
2525
string: str | bytes,
2626
fill: Callable[[int, int], _imaging.ImagingCore],
27-
mode: str,
28-
dir: str | None,
29-
features: list[str] | None,
30-
lang: str | None,
31-
stroke_width: float,
32-
stroke_filled: bool,
33-
anchor: str | None,
34-
foreground_ink_long: int,
35-
start: tuple[float, float],
27+
mode: str | None = ...,
28+
dir: str | None = ...,
29+
features: list[str] | None = ...,
30+
lang: str | None = ...,
31+
stroke_width: float = ...,
32+
stroke_filled: bool = ...,
33+
anchor: str | None = ...,
34+
foreground_ink_long: int = ...,
35+
start: tuple[float, float] = ...,
3636
/,
3737
) -> tuple[_imaging.ImagingCore, tuple[int, int]]: ...
3838
def getsize(
3939
self,
40-
string: str | bytes | bytearray,
41-
mode: str,
42-
dir: str | None,
43-
features: list[str] | None,
44-
lang: str | None,
45-
anchor: str | None,
40+
string: str | bytes,
41+
mode: str | None = ...,
42+
dir: str | None = ...,
43+
features: list[str] | None = ...,
44+
lang: str | None = ...,
45+
anchor: str | None = ...,
4646
/,
4747
) -> tuple[tuple[int, int], tuple[int, int]]: ...
4848
def getlength(
4949
self,
5050
string: str | bytes,
51-
mode: str,
52-
dir: str | None,
53-
features: list[str] | None,
54-
lang: str | None,
51+
mode: str | None = ...,
52+
dir: str | None = ...,
53+
features: list[str] | None = ...,
54+
lang: str | None = ...,
5555
/,
5656
) -> int: ...
5757
def getvarnames(self) -> list[bytes]: ...

0 commit comments

Comments
 (0)