Skip to content

Commit

Permalink
Merge pull request #7795 from radarhere/type_hints
Browse files Browse the repository at this point in the history
Use IO[bytes] in type hints
  • Loading branch information
radarhere committed Feb 15, 2024
2 parents 50e9a92 + 47eaf09 commit 912a33f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
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

0 comments on commit 912a33f

Please sign in to comment.