Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed May 10, 2024
2 parents b8e3e0a + bfbe339 commit 3344f57
Show file tree
Hide file tree
Showing 33 changed files with 91 additions and 83 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-cygwin.yml
Expand Up @@ -55,6 +55,7 @@ jobs:
packages: >
gcc-g++
ghostscript
git
ImageMagick
jpeg
libfreetype-devel
Expand Down Expand Up @@ -132,11 +133,12 @@ jobs:
bash.exe .ci/after_success.sh
- name: Upload coverage
uses: codecov/codecov-action@v3.1.5
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: GHA_Cygwin
name: Cygwin Python 3.${{ matrix.python-minor-version }}
token: ${{ secrets.CODECOV_ORG_TOKEN }}

success:
permissions:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-docker.yml
Expand Up @@ -100,11 +100,12 @@ jobs:
MATRIX_DOCKER: ${{ matrix.docker }}

- name: Upload coverage
uses: codecov/codecov-action@v3.1.5
uses: codecov/codecov-action@v4
with:
flags: GHA_Docker
name: ${{ matrix.docker }}
gcov: true
token: ${{ secrets.CODECOV_ORG_TOKEN }}

success:
permissions:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-mingw.yml
Expand Up @@ -85,8 +85,9 @@ jobs:
python3 -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests
- name: Upload coverage
uses: codecov/codecov-action@v3.1.5
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: GHA_Windows
name: "MSYS2 MinGW"
token: ${{ secrets.CODECOV_ORG_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/test-windows.yml
Expand Up @@ -213,11 +213,12 @@ jobs:
shell: pwsh

- name: Upload coverage
uses: codecov/codecov-action@v3.1.5
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: GHA_Windows
name: ${{ runner.os }} Python ${{ matrix.python-version }}
token: ${{ secrets.CODECOV_ORG_TOKEN }}

success:
permissions:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -150,11 +150,12 @@ jobs:
.ci/after_success.sh
- name: Upload coverage
uses: codecov/codecov-action@v3.1.5
uses: codecov/codecov-action@v4
with:
flags: ${{ matrix.os == 'ubuntu-latest' && 'GHA_Ubuntu' || 'GHA_macOS' }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
gcov: true
token: ${{ secrets.CODECOV_ORG_TOKEN }}

success:
permissions:
Expand Down
4 changes: 1 addition & 3 deletions Tests/test_file_eps.py
Expand Up @@ -336,9 +336,7 @@ def test_readline_psfile(tmp_path: Path) -> None:
strings = ["something", "else", "baz", "bif"]

def _test_readline(t: EpsImagePlugin.PSFile, ending: str) -> None:
ending = "Failure with line ending: %s" % (
"".join("%s" % ord(s) for s in ending)
)
ending = f"Failure with line ending: {''.join(str(ord(s)) for s in ending)}"
assert t.readline().strip("\r\n") == "something", ending
assert t.readline().strip("\r\n") == "else", ending
assert t.readline().strip("\r\n") == "baz", ending
Expand Down
10 changes: 5 additions & 5 deletions Tests/test_image_access.py
Expand Up @@ -409,13 +409,14 @@ def test_embeddable(self) -> None:
from setuptools.command import build_ext

with open("embed_pil.c", "w", encoding="utf-8") as fh:
home = sys.prefix.replace("\\", "\\\\")
fh.write(
"""
f"""
#include "Python.h"
int main(int argc, char* argv[])
{
char *home = "%s";
{{
char *home = "{home}";
wchar_t *whome = Py_DecodeLocale(home, NULL);
Py_SetPythonHome(whome);
Expand All @@ -430,9 +431,8 @@ def test_embeddable(self) -> None:
PyMem_RawFree(whome);
return 0;
}
}}
"""
% sys.prefix.replace("\\", "\\\\")
)

compiler = getattr(build_ext, "new_compiler")()
Expand Down
4 changes: 2 additions & 2 deletions selftest.py
Expand Up @@ -165,9 +165,9 @@ def testimage() -> None:
print("Running selftest:")
status = doctest.testmod(sys.modules[__name__])
if status[0]:
print("*** %s tests of %d failed." % status)
print(f"*** {status[0]} tests of {status[1]} failed.")
exit_status = 1
else:
print("--- %s tests passed." % status[1])
print(f"--- {status[1]} tests passed.")

sys.exit(exit_status)
6 changes: 3 additions & 3 deletions src/PIL/BlpImagePlugin.py
Expand Up @@ -253,7 +253,7 @@ class BlpImageFile(ImageFile.ImageFile):
format = "BLP"
format_description = "Blizzard Mipmap Format"

def _open(self):
def _open(self) -> None:
self.magic = self.fp.read(4)

self.fp.seek(5, os.SEEK_CUR)
Expand Down Expand Up @@ -333,7 +333,7 @@ def _read_bgra(self, palette):


class BLP1Decoder(_BLPBaseDecoder):
def _load(self):
def _load(self) -> None:
if self._blp_compression == Format.JPEG:
self._decode_jpeg_stream()

Expand Down Expand Up @@ -418,7 +418,7 @@ def _load(self):
class BLPEncoder(ImageFile.PyEncoder):
_pushes_fd = True

def _write_palette(self):
def _write_palette(self) -> bytes:
data = b""
palette = self.im.getpalette("RGBA", "RGBA")
for i in range(len(palette) // 4):
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/BmpImagePlugin.py
Expand Up @@ -283,7 +283,7 @@ def _bitmap(self, header=0, offset=0):
)
]

def _open(self):
def _open(self) -> None:
"""Open file, check magic number and read header"""
# read 14 bytes: magic number, filesize, reserved, header final offset
head_data = self.fp.read(14)
Expand Down Expand Up @@ -376,7 +376,7 @@ class DibImageFile(BmpImageFile):
format = "DIB"
format_description = "Windows Bitmap"

def _open(self):
def _open(self) -> None:
self._bitmap()


Expand Down
4 changes: 2 additions & 2 deletions src/PIL/DcxImagePlugin.py
Expand Up @@ -63,15 +63,15 @@ def _open(self):
self.is_animated = self.n_frames > 1
self.seek(0)

def seek(self, frame):
def seek(self, frame: int) -> None:
if not self._seek_check(frame):
return
self.frame = frame
self.fp = self._fp
self.fp.seek(self._offset[frame])
PcxImageFile._open(self)

def tell(self):
def tell(self) -> int:
return self.frame


Expand Down
2 changes: 1 addition & 1 deletion src/PIL/DdsImagePlugin.py
Expand Up @@ -331,7 +331,7 @@ class DdsImageFile(ImageFile.ImageFile):
format = "DDS"
format_description = "DirectDraw Surface"

def _open(self):
def _open(self) -> None:
if not _accept(self.fp.read(4)):
msg = "not a DDS file"
raise SyntaxError(msg)
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/EpsImagePlugin.py
Expand Up @@ -178,7 +178,7 @@ def seek(self, offset, whence=io.SEEK_SET):
self.char = None
self.fp.seek(offset, whence)

def readline(self):
def readline(self) -> str:
s = [self.char or b""]
self.char = None

Expand Down Expand Up @@ -212,7 +212,7 @@ class EpsImageFile(ImageFile.ImageFile):

mode_map = {1: "L", 2: "LAB", 3: "RGB", 4: "CMYK"}

def _open(self):
def _open(self) -> None:
(length, offset) = self._find_offset(self.fp)

# go to offset - start of "%!PS"
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/FliImagePlugin.py
Expand Up @@ -123,7 +123,7 @@ def _palette(self, palette, shift):
palette[i] = (r, g, b)
i += 1

def seek(self, frame):
def seek(self, frame: int) -> None:
if not self._seek_check(frame):
return
if frame < self.__frame:
Expand Down Expand Up @@ -162,7 +162,7 @@ def _seek(self, frame):

self.__offset += framesize

def tell(self):
def tell(self) -> int:
return self.__frame


Expand Down
12 changes: 6 additions & 6 deletions src/PIL/GifImagePlugin.py
Expand Up @@ -76,7 +76,7 @@ class GifImageFile(ImageFile.ImageFile):

global_palette = None

def data(self):
def data(self) -> bytes | None:
s = self.fp.read(1)
if s and s[0]:
return self.fp.read(s[0])
Expand All @@ -88,7 +88,7 @@ def _is_palette_needed(self, p):
return True
return False

def _open(self):
def _open(self) -> None:
# Screen
s = self.fp.read(13)
if not _accept(s):
Expand Down Expand Up @@ -147,7 +147,7 @@ def is_animated(self):
self.seek(current)
return self._is_animated

def seek(self, frame):
def seek(self, frame: int) -> None:
if not self._seek_check(frame):
return
if frame < self.__frame:
Expand Down Expand Up @@ -417,7 +417,7 @@ def _rgb(color):
elif k in self.info:
del self.info[k]

def load_prepare(self):
def load_prepare(self) -> None:
temp_mode = "P" if self._frame_palette else "L"
self._prev_im = None
if self.__frame == 0:
Expand All @@ -437,7 +437,7 @@ def load_prepare(self):

super().load_prepare()

def load_end(self):
def load_end(self) -> None:
if self.__frame == 0:
if self.mode == "P" and LOADING_STRATEGY == LoadingStrategy.RGB_ALWAYS:
if self._frame_transparency is not None:
Expand All @@ -463,7 +463,7 @@ def load_end(self):
else:
self.im.paste(frame_im, self.dispose_extent)

def tell(self):
def tell(self) -> int:
return self.__frame


Expand Down
2 changes: 1 addition & 1 deletion src/PIL/Hdf5StubImagePlugin.py
Expand Up @@ -37,7 +37,7 @@ class HDF5StubImageFile(ImageFile.StubImageFile):
format = "HDF5"
format_description = "HDF5"

def _open(self):
def _open(self) -> None:
offset = self.fp.tell()

if not _accept(self.fp.read(8)):
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/IcnsImagePlugin.py
Expand Up @@ -252,7 +252,7 @@ class IcnsImageFile(ImageFile.ImageFile):
format = "ICNS"
format_description = "Mac OS icns resource"

def _open(self):
def _open(self) -> None:
self.icns = IcnsFile(self.fp)
self._mode = "RGBA"
self.info["sizes"] = self.icns.itersizes()
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/IcoImagePlugin.py
Expand Up @@ -302,7 +302,7 @@ class IcoImageFile(ImageFile.ImageFile):
format = "ICO"
format_description = "Windows Icon"

def _open(self):
def _open(self) -> None:
self.ico = IcoFile(self.fp)
self.info["sizes"] = self.ico.sizes()
self.size = self.ico.entry[0]["dim"]
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/ImImagePlugin.py
Expand Up @@ -278,7 +278,7 @@ def n_frames(self):
def is_animated(self):
return self.info[FRAMES] > 1

def seek(self, frame):
def seek(self, frame: int) -> None:
if not self._seek_check(frame):
return

Expand All @@ -296,7 +296,7 @@ def seek(self, frame):

self.tile = [("raw", (0, 0) + self.size, offs, (self.rawmode, 0, -1))]

def tell(self):
def tell(self) -> int:
return self.frame


Expand Down
7 changes: 5 additions & 2 deletions src/PIL/Image.py
Expand Up @@ -1298,7 +1298,10 @@ def _expand(self, xmargin: int, ymargin: int | None = None) -> Image:
self.load()
return self._new(self.im.expand(xmargin, ymargin))

def filter(self, filter):
if TYPE_CHECKING:
from . import ImageFilter

def filter(self, filter: ImageFilter.Filter | type[ImageFilter.Filter]) -> Image:
"""
Filters this image using the given filter. For a list of
available filters, see the :py:mod:`~PIL.ImageFilter` module.
Expand All @@ -1310,7 +1313,7 @@ def filter(self, filter):

self.load()

if isinstance(filter, Callable):
if callable(filter):
filter = filter()
if not hasattr(filter, "filter"):
msg = "filter argument should be ImageFilter.Filter instance or class"
Expand Down
10 changes: 5 additions & 5 deletions src/PIL/ImageFile.py
Expand Up @@ -311,15 +311,15 @@ def load(self):

return Image.Image.load(self)

def load_prepare(self):
def load_prepare(self) -> None:
# create image memory if necessary
if not self.im or self.im.mode != self.mode or self.im.size != self.size:
self.im = Image.core.new(self.mode, self.size)
# create palette (optional)
if self.mode == "P":
Image.Image.load(self)

def load_end(self):
def load_end(self) -> None:
# may be overridden
pass

Expand Down Expand Up @@ -390,7 +390,7 @@ class Parser:
offset = 0
finished = 0

def reset(self):
def reset(self) -> None:
"""
(Consumer) Reset the parser. Note that you can only call this
method immediately after you've created a parser; parser
Expand Down Expand Up @@ -605,7 +605,7 @@ def _safe_read(fp, size):


class PyCodecState:
def __init__(self):
def __init__(self) -> None:
self.xsize = 0
self.ysize = 0
self.xoff = 0
Expand Down Expand Up @@ -634,7 +634,7 @@ def init(self, args):
"""
self.args = args

def cleanup(self):
def cleanup(self) -> None:
"""
Override to perform codec specific cleanup
Expand Down

0 comments on commit 3344f57

Please sign in to comment.