Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IO[bytes] in type hints #7795

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import itertools
import struct
import sys
from typing import Any, NamedTuple
from typing import IO, Any, NamedTuple

from . import Image
from ._deprecate import deprecate
Expand Down Expand Up @@ -616,7 +616,7 @@ def extents(self):


class PyCodec:
fd: io.BytesIO | None
fd: IO[bytes] | None

def __init__(self, mode, *args):
self.im = None
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/MspImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import io
import struct
from typing import IO

from . import Image, ImageFile
from ._binary import i16le as i16
Expand Down Expand Up @@ -163,7 +164,7 @@ def decode(self, buffer: bytes) -> tuple[int, int]:
# write MSP files (uncompressed only)


def _save(im: Image.Image, fp: io.BytesIO, filename: str) -> None:
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None:
if im.mode != "1":
msg = f"cannot write mode {im.mode} as MSP"
raise OSError(msg)
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/PcxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import io
import logging
from typing import IO

from . import Image, ImageFile, ImagePalette
from ._binary import i16le as i16
Expand Down Expand Up @@ -143,7 +144,7 @@ def _open(self) -> None:
}


def _save(im: Image.Image, fp: io.BytesIO, filename: str) -> None:
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None:
try:
version, bits, planes, rawmode = SAVE[im.mode]
except KeyError as e:
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/PpmImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from __future__ import annotations

import math
from io import BytesIO
from typing import IO

from . import Image, ImageFile
from ._binary import i16be as i16
Expand Down Expand Up @@ -324,7 +324,7 @@ def decode(self, buffer: bytes) -> tuple[int, int]:
# --------------------------------------------------------------------


def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None:
if im.mode == "1":
rawmode, head = "1;I", b"P4"
elif im.mode == "L":
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/SgiImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import os
import struct
from io import BytesIO
from typing import IO

from . import Image, ImageFile
from ._binary import i16be as i16
Expand Down Expand Up @@ -125,7 +125,7 @@ def _open(self) -> None:
]


def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None:
if im.mode not in {"RGB", "RGBA", "L"}:
msg = "Unsupported SGI image mode"
raise ValueError(msg)
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/TgaImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from __future__ import annotations

import warnings
from io import BytesIO
from typing import IO

from . import Image, ImageFile, ImagePalette
from ._binary import i16le as i16
Expand Down Expand Up @@ -175,7 +175,7 @@ def load_end(self) -> None:
}


def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None:
try:
rawmode, bits, colormaptype, imagetype = SAVE[im.mode]
except KeyError as e:
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/XbmImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from __future__ import annotations

import re
from io import BytesIO
from typing import IO

from . import Image, ImageFile

Expand Down Expand Up @@ -70,7 +70,7 @@ def _open(self) -> None:
self.tile = [("xbm", (0, 0) + self.size, m.end(), None)]


def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None:
if im.mode != "1":
msg = f"cannot write mode {im.mode} as XBM"
raise OSError(msg)
Expand Down
Loading