mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Use IO[bytes] in type hints
This commit is contained in:
parent
50e9a92c98
commit
47eaf0937f
|
@ -32,7 +32,7 @@ import io
|
||||||
import itertools
|
import itertools
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, NamedTuple
|
from typing import IO, Any, NamedTuple
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._deprecate import deprecate
|
from ._deprecate import deprecate
|
||||||
|
@ -616,7 +616,7 @@ class PyCodecState:
|
||||||
|
|
||||||
|
|
||||||
class PyCodec:
|
class PyCodec:
|
||||||
fd: io.BytesIO | None
|
fd: IO[bytes] | None
|
||||||
|
|
||||||
def __init__(self, mode, *args):
|
def __init__(self, mode, *args):
|
||||||
self.im = None
|
self.im = None
|
||||||
|
|
|
@ -26,6 +26,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import struct
|
import struct
|
||||||
|
from typing import IO
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
from ._binary import i16le as i16
|
from ._binary import i16le as i16
|
||||||
|
@ -163,7 +164,7 @@ Image.register_decoder("MSP", MspDecoder)
|
||||||
# write MSP files (uncompressed only)
|
# 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":
|
if im.mode != "1":
|
||||||
msg = f"cannot write mode {im.mode} as MSP"
|
msg = f"cannot write mode {im.mode} as MSP"
|
||||||
raise OSError(msg)
|
raise OSError(msg)
|
||||||
|
|
|
@ -28,6 +28,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
|
from typing import IO
|
||||||
|
|
||||||
from . import Image, ImageFile, ImagePalette
|
from . import Image, ImageFile, ImagePalette
|
||||||
from ._binary import i16le as i16
|
from ._binary import i16le as i16
|
||||||
|
@ -143,7 +144,7 @@ SAVE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _save(im: Image.Image, fp: io.BytesIO, filename: str) -> None:
|
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None:
|
||||||
try:
|
try:
|
||||||
version, bits, planes, rawmode = SAVE[im.mode]
|
version, bits, planes, rawmode = SAVE[im.mode]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import math
|
import math
|
||||||
from io import BytesIO
|
from typing import IO
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
from ._binary import i16be as i16
|
from ._binary import i16be as i16
|
||||||
|
@ -324,7 +324,7 @@ class PpmDecoder(ImageFile.PyDecoder):
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
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":
|
if im.mode == "1":
|
||||||
rawmode, head = "1;I", b"P4"
|
rawmode, head = "1;I", b"P4"
|
||||||
elif im.mode == "L":
|
elif im.mode == "L":
|
||||||
|
|
|
@ -24,7 +24,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
from io import BytesIO
|
from typing import IO
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
from ._binary import i16be as i16
|
from ._binary import i16be as i16
|
||||||
|
@ -125,7 +125,7 @@ class SgiImageFile(ImageFile.ImageFile):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
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"}:
|
if im.mode not in {"RGB", "RGBA", "L"}:
|
||||||
msg = "Unsupported SGI image mode"
|
msg = "Unsupported SGI image mode"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
from io import BytesIO
|
from typing import IO
|
||||||
|
|
||||||
from . import Image, ImageFile, ImagePalette
|
from . import Image, ImageFile, ImagePalette
|
||||||
from ._binary import i16le as i16
|
from ._binary import i16le as i16
|
||||||
|
@ -175,7 +175,7 @@ SAVE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
|
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None:
|
||||||
try:
|
try:
|
||||||
rawmode, bits, colormaptype, imagetype = SAVE[im.mode]
|
rawmode, bits, colormaptype, imagetype = SAVE[im.mode]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from io import BytesIO
|
from typing import IO
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class XbmImageFile(ImageFile.ImageFile):
|
||||||
self.tile = [("xbm", (0, 0) + self.size, m.end(), 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":
|
if im.mode != "1":
|
||||||
msg = f"cannot write mode {im.mode} as XBM"
|
msg = f"cannot write mode {im.mode} as XBM"
|
||||||
raise OSError(msg)
|
raise OSError(msg)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user