Skip to content

Commit 958a651

Browse files
authored
Merge pull request #112 from radarhere/type-hints-replace-io.BytesIO
2 parents 159fc06 + 152a24e commit 958a651

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/PIL/Image.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,7 @@ def save(self, fp, format=None, **params) -> None:
23852385
filename = ""
23862386
open_fp = False
23872387
if is_path(fp):
2388-
filename = os.fspath(fp)
2388+
filename = os.path.realpath(os.fspath(fp))
23892389
open_fp = True
23902390
elif fp == sys.stdout:
23912391
try:
@@ -3240,10 +3240,8 @@ def open(fp, mode="r", formats=None) -> Image:
32403240

32413241
exclusive_fp = False
32423242
filename = ""
3243-
if isinstance(fp, os.PathLike):
3243+
if is_path(fp):
32443244
filename = os.path.realpath(os.fspath(fp))
3245-
elif is_path(fp):
3246-
filename = fp
32473245

32483246
if filename:
32493247
fp = builtins.open(filename, "rb")

src/PIL/ImageFont.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
import warnings
3434
from enum import IntEnum
3535
from io import BytesIO
36-
from pathlib import Path
3736
from typing import BinaryIO
3837

3938
from . import Image
39+
from ._typing import StrOrBytesPath
4040
from ._util import is_directory, is_path
4141

4242

@@ -193,7 +193,7 @@ class FreeTypeFont:
193193

194194
def __init__(
195195
self,
196-
font: bytes | str | Path | BinaryIO | None = None,
196+
font: StrOrBytesPath | BinaryIO | None = None,
197197
size: float = 10,
198198
index: int = 0,
199199
encoding: str = "",
@@ -230,7 +230,7 @@ def load_from_bytes(f):
230230
)
231231

232232
if is_path(font):
233-
font = os.fspath(font)
233+
font = os.path.realpath(os.fspath(font))
234234
if sys.platform == "win32":
235235
font_bytes_path = font if isinstance(font, bytes) else font.encode()
236236
try:

0 commit comments

Comments
 (0)