Merge pull request #112 from radarhere/type-hints-replace-io.BytesIO

This commit is contained in:
Hugo van Kemenade 2024-02-10 11:43:29 +02:00 committed by GitHub
commit 958a651449
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 7 deletions

View File

@ -2385,7 +2385,7 @@ class Image:
filename = "" filename = ""
open_fp = False open_fp = False
if is_path(fp): if is_path(fp):
filename = os.fspath(fp) filename = os.path.realpath(os.fspath(fp))
open_fp = True open_fp = True
elif fp == sys.stdout: elif fp == sys.stdout:
try: try:
@ -3240,10 +3240,8 @@ def open(fp, mode="r", formats=None) -> Image:
exclusive_fp = False exclusive_fp = False
filename = "" filename = ""
if isinstance(fp, os.PathLike): if is_path(fp):
filename = os.path.realpath(os.fspath(fp)) filename = os.path.realpath(os.fspath(fp))
elif is_path(fp):
filename = fp
if filename: if filename:
fp = builtins.open(filename, "rb") fp = builtins.open(filename, "rb")

View File

@ -33,10 +33,10 @@ import sys
import warnings import warnings
from enum import IntEnum from enum import IntEnum
from io import BytesIO from io import BytesIO
from pathlib import Path
from typing import BinaryIO from typing import BinaryIO
from . import Image from . import Image
from ._typing import StrOrBytesPath
from ._util import is_directory, is_path from ._util import is_directory, is_path
@ -193,7 +193,7 @@ class FreeTypeFont:
def __init__( def __init__(
self, self,
font: bytes | str | Path | BinaryIO | None = None, font: StrOrBytesPath | BinaryIO | None = None,
size: float = 10, size: float = 10,
index: int = 0, index: int = 0,
encoding: str = "", encoding: str = "",
@ -230,7 +230,7 @@ class FreeTypeFont:
) )
if is_path(font): if is_path(font):
font = os.fspath(font) font = os.path.realpath(os.fspath(font))
if sys.platform == "win32": if sys.platform == "win32":
font_bytes_path = font if isinstance(font, bytes) else font.encode() font_bytes_path = font if isinstance(font, bytes) else font.encode()
try: try: