mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 02:46:18 +03:00
Merge branch 'main' into type_hints
This commit is contained in:
commit
b2ce2f6ec4
4
.github/workflows/test-cygwin.yml
vendored
4
.github/workflows/test-cygwin.yml
vendored
|
@ -55,6 +55,7 @@ jobs:
|
||||||
packages: >
|
packages: >
|
||||||
gcc-g++
|
gcc-g++
|
||||||
ghostscript
|
ghostscript
|
||||||
|
git
|
||||||
ImageMagick
|
ImageMagick
|
||||||
jpeg
|
jpeg
|
||||||
libfreetype-devel
|
libfreetype-devel
|
||||||
|
@ -132,11 +133,12 @@ jobs:
|
||||||
bash.exe .ci/after_success.sh
|
bash.exe .ci/after_success.sh
|
||||||
|
|
||||||
- name: Upload coverage
|
- name: Upload coverage
|
||||||
uses: codecov/codecov-action@v3.1.5
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
file: ./coverage.xml
|
file: ./coverage.xml
|
||||||
flags: GHA_Cygwin
|
flags: GHA_Cygwin
|
||||||
name: Cygwin Python 3.${{ matrix.python-minor-version }}
|
name: Cygwin Python 3.${{ matrix.python-minor-version }}
|
||||||
|
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||||
|
|
||||||
success:
|
success:
|
||||||
permissions:
|
permissions:
|
||||||
|
|
3
.github/workflows/test-docker.yml
vendored
3
.github/workflows/test-docker.yml
vendored
|
@ -100,11 +100,12 @@ jobs:
|
||||||
MATRIX_DOCKER: ${{ matrix.docker }}
|
MATRIX_DOCKER: ${{ matrix.docker }}
|
||||||
|
|
||||||
- name: Upload coverage
|
- name: Upload coverage
|
||||||
uses: codecov/codecov-action@v3.1.5
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
flags: GHA_Docker
|
flags: GHA_Docker
|
||||||
name: ${{ matrix.docker }}
|
name: ${{ matrix.docker }}
|
||||||
gcov: true
|
gcov: true
|
||||||
|
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||||
|
|
||||||
success:
|
success:
|
||||||
permissions:
|
permissions:
|
||||||
|
|
3
.github/workflows/test-mingw.yml
vendored
3
.github/workflows/test-mingw.yml
vendored
|
@ -85,8 +85,9 @@ jobs:
|
||||||
python3 -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests
|
python3 -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests
|
||||||
|
|
||||||
- name: Upload coverage
|
- name: Upload coverage
|
||||||
uses: codecov/codecov-action@v3.1.5
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
file: ./coverage.xml
|
file: ./coverage.xml
|
||||||
flags: GHA_Windows
|
flags: GHA_Windows
|
||||||
name: "MSYS2 MinGW"
|
name: "MSYS2 MinGW"
|
||||||
|
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||||
|
|
3
.github/workflows/test-windows.yml
vendored
3
.github/workflows/test-windows.yml
vendored
|
@ -213,11 +213,12 @@ jobs:
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
|
|
||||||
- name: Upload coverage
|
- name: Upload coverage
|
||||||
uses: codecov/codecov-action@v3.1.5
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
file: ./coverage.xml
|
file: ./coverage.xml
|
||||||
flags: GHA_Windows
|
flags: GHA_Windows
|
||||||
name: ${{ runner.os }} Python ${{ matrix.python-version }}
|
name: ${{ runner.os }} Python ${{ matrix.python-version }}
|
||||||
|
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||||
|
|
||||||
success:
|
success:
|
||||||
permissions:
|
permissions:
|
||||||
|
|
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
|
@ -150,11 +150,12 @@ jobs:
|
||||||
.ci/after_success.sh
|
.ci/after_success.sh
|
||||||
|
|
||||||
- name: Upload coverage
|
- name: Upload coverage
|
||||||
uses: codecov/codecov-action@v3.1.5
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
flags: ${{ matrix.os == 'ubuntu-latest' && 'GHA_Ubuntu' || 'GHA_macOS' }}
|
flags: ${{ matrix.os == 'ubuntu-latest' && 'GHA_Ubuntu' || 'GHA_macOS' }}
|
||||||
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
|
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
|
||||||
gcov: true
|
gcov: true
|
||||||
|
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||||
|
|
||||||
success:
|
success:
|
||||||
permissions:
|
permissions:
|
||||||
|
|
|
@ -271,16 +271,16 @@ class D3DFMT(IntEnum):
|
||||||
module = sys.modules[__name__]
|
module = sys.modules[__name__]
|
||||||
for item in DDSD:
|
for item in DDSD:
|
||||||
assert item.name is not None
|
assert item.name is not None
|
||||||
setattr(module, "DDSD_" + item.name, item.value)
|
setattr(module, f"DDSD_{item.name}", item.value)
|
||||||
for item1 in DDSCAPS:
|
for item1 in DDSCAPS:
|
||||||
assert item1.name is not None
|
assert item1.name is not None
|
||||||
setattr(module, "DDSCAPS_" + item1.name, item1.value)
|
setattr(module, f"DDSCAPS_{item1.name}", item1.value)
|
||||||
for item2 in DDSCAPS2:
|
for item2 in DDSCAPS2:
|
||||||
assert item2.name is not None
|
assert item2.name is not None
|
||||||
setattr(module, "DDSCAPS2_" + item2.name, item2.value)
|
setattr(module, f"DDSCAPS2_{item2.name}", item2.value)
|
||||||
for item3 in DDPF:
|
for item3 in DDPF:
|
||||||
assert item3.name is not None
|
assert item3.name is not None
|
||||||
setattr(module, "DDPF_" + item3.name, item3.value)
|
setattr(module, f"DDPF_{item3.name}", item3.value)
|
||||||
|
|
||||||
DDS_FOURCC = DDPF.FOURCC
|
DDS_FOURCC = DDPF.FOURCC
|
||||||
DDS_RGB = DDPF.RGB
|
DDS_RGB = DDPF.RGB
|
||||||
|
|
|
@ -196,7 +196,7 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
msg = "Syntax error in IM header: " + s.decode("ascii", "replace")
|
msg = f"Syntax error in IM header: {s.decode('ascii', 'replace')}"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
|
||||||
if not n:
|
if not n:
|
||||||
|
|
|
@ -414,7 +414,7 @@ def _getdecoder(mode, decoder_name, args, extra=()):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# get decoder
|
# get decoder
|
||||||
decoder = getattr(core, decoder_name + "_decoder")
|
decoder = getattr(core, f"{decoder_name}_decoder")
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
msg = f"decoder {decoder_name} not available"
|
msg = f"decoder {decoder_name} not available"
|
||||||
raise OSError(msg) from e
|
raise OSError(msg) from e
|
||||||
|
@ -437,7 +437,7 @@ def _getencoder(mode, encoder_name, args, extra=()):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# get encoder
|
# get encoder
|
||||||
encoder = getattr(core, encoder_name + "_encoder")
|
encoder = getattr(core, f"{encoder_name}_encoder")
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
msg = f"encoder {encoder_name} not available"
|
msg = f"encoder {encoder_name} not available"
|
||||||
raise OSError(msg) from e
|
raise OSError(msg) from e
|
||||||
|
@ -637,7 +637,7 @@ class Image:
|
||||||
) -> str:
|
) -> str:
|
||||||
suffix = ""
|
suffix = ""
|
||||||
if format:
|
if format:
|
||||||
suffix = "." + format
|
suffix = f".{format}"
|
||||||
|
|
||||||
if not file:
|
if not file:
|
||||||
f, filename = tempfile.mkstemp(suffix)
|
f, filename = tempfile.mkstemp(suffix)
|
||||||
|
@ -2216,7 +2216,7 @@ class Image:
|
||||||
(Resampling.HAMMING, "Image.Resampling.HAMMING"),
|
(Resampling.HAMMING, "Image.Resampling.HAMMING"),
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
msg += " Use " + ", ".join(filters[:-1]) + " or " + filters[-1]
|
msg += f" Use {', '.join(filters[:-1])} or {filters[-1]}"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
if reducing_gap is not None and reducing_gap < 1.0:
|
if reducing_gap is not None and reducing_gap < 1.0:
|
||||||
|
@ -2861,7 +2861,7 @@ class Image:
|
||||||
(Resampling.BICUBIC, "Image.Resampling.BICUBIC"),
|
(Resampling.BICUBIC, "Image.Resampling.BICUBIC"),
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
msg += " Use " + ", ".join(filters[:-1]) + " or " + filters[-1]
|
msg += f" Use {', '.join(filters[:-1])} or {filters[-1]}"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
image.load()
|
image.load()
|
||||||
|
@ -3259,8 +3259,8 @@ _fromarray_typemap = {
|
||||||
((1, 1, 3), "|u1"): ("RGB", "RGB"),
|
((1, 1, 3), "|u1"): ("RGB", "RGB"),
|
||||||
((1, 1, 4), "|u1"): ("RGBA", "RGBA"),
|
((1, 1, 4), "|u1"): ("RGBA", "RGBA"),
|
||||||
# shortcuts:
|
# shortcuts:
|
||||||
((1, 1), _ENDIAN + "i4"): ("I", "I"),
|
((1, 1), f"{_ENDIAN}i4"): ("I", "I"),
|
||||||
((1, 1), _ENDIAN + "f4"): ("F", "F"),
|
((1, 1), f"{_ENDIAN}f4"): ("F", "F"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ class _Operand:
|
||||||
out = Image.new(mode or im_1.mode, im_1.size, None)
|
out = Image.new(mode or im_1.mode, im_1.size, None)
|
||||||
im_1.load()
|
im_1.load()
|
||||||
try:
|
try:
|
||||||
op = getattr(_imagingmath, op + "_" + im_1.mode)
|
op = getattr(_imagingmath, f"{op}_{im_1.mode}")
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
msg = f"bad operand type for '{op}'"
|
msg = f"bad operand type for '{op}'"
|
||||||
raise TypeError(msg) from e
|
raise TypeError(msg) from e
|
||||||
|
@ -89,7 +89,7 @@ class _Operand:
|
||||||
im_1.load()
|
im_1.load()
|
||||||
im_2.load()
|
im_2.load()
|
||||||
try:
|
try:
|
||||||
op = getattr(_imagingmath, op + "_" + im_1.mode)
|
op = getattr(_imagingmath, f"{op}_{im_1.mode}")
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
msg = f"bad operand type for '{op}'"
|
msg = f"bad operand type for '{op}'"
|
||||||
raise TypeError(msg) from e
|
raise TypeError(msg) from e
|
||||||
|
|
|
@ -44,8 +44,8 @@ def getmode(mode: str) -> ModeDescriptor:
|
||||||
# Bits need to be extended to bytes
|
# Bits need to be extended to bytes
|
||||||
"1": ("L", "L", ("1",), "|b1"),
|
"1": ("L", "L", ("1",), "|b1"),
|
||||||
"L": ("L", "L", ("L",), "|u1"),
|
"L": ("L", "L", ("L",), "|u1"),
|
||||||
"I": ("L", "I", ("I",), endian + "i4"),
|
"I": ("L", "I", ("I",), f"{endian}i4"),
|
||||||
"F": ("L", "F", ("F",), endian + "f4"),
|
"F": ("L", "F", ("F",), f"{endian}f4"),
|
||||||
"P": ("P", "L", ("P",), "|u1"),
|
"P": ("P", "L", ("P",), "|u1"),
|
||||||
"RGB": ("RGB", "L", ("R", "G", "B"), "|u1"),
|
"RGB": ("RGB", "L", ("R", "G", "B"), "|u1"),
|
||||||
"RGBX": ("RGB", "L", ("R", "G", "B", "X"), "|u1"),
|
"RGBX": ("RGB", "L", ("R", "G", "B", "X"), "|u1"),
|
||||||
|
@ -78,8 +78,8 @@ def getmode(mode: str) -> ModeDescriptor:
|
||||||
"I;16LS": "<i2",
|
"I;16LS": "<i2",
|
||||||
"I;16B": ">u2",
|
"I;16B": ">u2",
|
||||||
"I;16BS": ">i2",
|
"I;16BS": ">i2",
|
||||||
"I;16N": endian + "u2",
|
"I;16N": f"{endian}u2",
|
||||||
"I;16NS": endian + "i2",
|
"I;16NS": f"{endian}i2",
|
||||||
"I;32": "<u4",
|
"I;32": "<u4",
|
||||||
"I;32B": ">u4",
|
"I;32B": ">u4",
|
||||||
"I;32L": "<u4",
|
"I;32L": "<u4",
|
||||||
|
|
|
@ -84,7 +84,7 @@ class LutBuilder:
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
if op_name not in known_patterns:
|
if op_name not in known_patterns:
|
||||||
msg = "Unknown pattern " + op_name + "!"
|
msg = f"Unknown pattern {op_name}!"
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
|
|
||||||
self.patterns = known_patterns[op_name]
|
self.patterns = known_patterns[op_name]
|
||||||
|
|
|
@ -196,7 +196,7 @@ class Window:
|
||||||
)
|
)
|
||||||
|
|
||||||
def __dispatcher(self, action, *args):
|
def __dispatcher(self, action, *args):
|
||||||
return getattr(self, "ui_handle_" + action)(*args)
|
return getattr(self, f"ui_handle_{action}")(*args)
|
||||||
|
|
||||||
def ui_handle_clear(self, dc, x0, y0, x1, y1):
|
def ui_handle_clear(self, dc, x0, y0, x1, y1):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -142,7 +142,7 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
# we ignore the palette here
|
# we ignore the palette here
|
||||||
im.mode = "P"
|
im.mode = "P"
|
||||||
rawmode = "P;" + str(bpp)
|
rawmode = f"P;{bpp}"
|
||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
elif im.mode == "1":
|
elif im.mode == "1":
|
||||||
|
|
|
@ -144,9 +144,7 @@ class XrefTable:
|
||||||
elif key in self.deleted_entries:
|
elif key in self.deleted_entries:
|
||||||
generation = self.deleted_entries[key]
|
generation = self.deleted_entries[key]
|
||||||
else:
|
else:
|
||||||
msg = (
|
msg = f"object ID {key} cannot be deleted because it doesn't exist"
|
||||||
"object ID " + str(key) + " cannot be deleted because it doesn't exist"
|
|
||||||
)
|
|
||||||
raise IndexError(msg)
|
raise IndexError(msg)
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
|
@ -225,7 +223,7 @@ class PdfName:
|
||||||
return hash(self.name)
|
return hash(self.name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"PdfName({repr(self.name)})"
|
return f"{self.__class__.__name__}({repr(self.name)})"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_pdf_stream(cls, data):
|
def from_pdf_stream(cls, data):
|
||||||
|
@ -884,7 +882,7 @@ class PdfParser:
|
||||||
if m:
|
if m:
|
||||||
return cls.get_literal_string(data, m.end())
|
return cls.get_literal_string(data, m.end())
|
||||||
# return None, offset # fallback (only for debugging)
|
# return None, offset # fallback (only for debugging)
|
||||||
msg = "unrecognized object: " + repr(data[offset : offset + 32])
|
msg = f"unrecognized object: {repr(data[offset : offset + 32])}"
|
||||||
raise PdfFormatError(msg)
|
raise PdfFormatError(msg)
|
||||||
|
|
||||||
re_lit_str_token = re.compile(
|
re_lit_str_token = re.compile(
|
||||||
|
|
|
@ -189,7 +189,7 @@ class ChunkStream:
|
||||||
"""Call the appropriate chunk handler"""
|
"""Call the appropriate chunk handler"""
|
||||||
|
|
||||||
logger.debug("STREAM %r %s %s", cid, pos, length)
|
logger.debug("STREAM %r %s %s", cid, pos, length)
|
||||||
return getattr(self, "chunk_" + cid.decode("ascii"))(pos, length)
|
return getattr(self, f"chunk_{cid.decode('ascii')}")(pos, length)
|
||||||
|
|
||||||
def crc(self, cid, data):
|
def crc(self, cid, data):
|
||||||
"""Read and verify checksum"""
|
"""Read and verify checksum"""
|
||||||
|
|
|
@ -218,7 +218,7 @@ def loadImageSeries(filelist=None):
|
||||||
im = im.convert2byte()
|
im = im.convert2byte()
|
||||||
except Exception:
|
except Exception:
|
||||||
if not isSpiderImage(img):
|
if not isSpiderImage(img):
|
||||||
print(img + " is not a Spider image file")
|
print(f"{img} is not a Spider image file")
|
||||||
continue
|
continue
|
||||||
im.info["filename"] = img
|
im.info["filename"] = img
|
||||||
imglist.append(im)
|
imglist.append(im)
|
||||||
|
@ -299,10 +299,10 @@ if __name__ == "__main__":
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
with Image.open(filename) as im:
|
with Image.open(filename) as im:
|
||||||
print("image: " + str(im))
|
print(f"image: {im}")
|
||||||
print("format: " + str(im.format))
|
print(f"format: {im.format}")
|
||||||
print("size: " + str(im.size))
|
print(f"size: {im.size}")
|
||||||
print("mode: " + str(im.mode))
|
print(f"mode: {im.mode}")
|
||||||
print("max, min: ", end=" ")
|
print("max, min: ", end=" ")
|
||||||
print(im.getextrema())
|
print(im.getextrema())
|
||||||
|
|
||||||
|
|
|
@ -469,7 +469,7 @@ def _register_basic(idx_fmt_name):
|
||||||
|
|
||||||
idx, fmt, name = idx_fmt_name
|
idx, fmt, name = idx_fmt_name
|
||||||
TYPES[idx] = name
|
TYPES[idx] = name
|
||||||
size = struct.calcsize("=" + fmt)
|
size = struct.calcsize(f"={fmt}")
|
||||||
_load_dispatch[idx] = ( # noqa: F821
|
_load_dispatch[idx] = ( # noqa: F821
|
||||||
size,
|
size,
|
||||||
lambda self, data, legacy_api=True: (
|
lambda self, data, legacy_api=True: (
|
||||||
|
@ -987,8 +987,8 @@ ImageFileDirectory_v2._load_dispatch = _load_dispatch
|
||||||
ImageFileDirectory_v2._write_dispatch = _write_dispatch
|
ImageFileDirectory_v2._write_dispatch = _write_dispatch
|
||||||
for idx, name in TYPES.items():
|
for idx, name in TYPES.items():
|
||||||
name = name.replace(" ", "_")
|
name = name.replace(" ", "_")
|
||||||
setattr(ImageFileDirectory_v2, "load_" + name, _load_dispatch[idx][1])
|
setattr(ImageFileDirectory_v2, f"load_{name}", _load_dispatch[idx][1])
|
||||||
setattr(ImageFileDirectory_v2, "write_" + name, _write_dispatch[idx])
|
setattr(ImageFileDirectory_v2, f"write_{name}", _write_dispatch[idx])
|
||||||
del _load_dispatch, _write_dispatch, idx, name
|
del _load_dispatch, _write_dispatch, idx, name
|
||||||
|
|
||||||
|
|
||||||
|
@ -2025,9 +2025,9 @@ class AppendingTiffWriter:
|
||||||
|
|
||||||
def setEndian(self, endian):
|
def setEndian(self, endian):
|
||||||
self.endian = endian
|
self.endian = endian
|
||||||
self.longFmt = self.endian + "L"
|
self.longFmt = f"{self.endian}L"
|
||||||
self.shortFmt = self.endian + "H"
|
self.shortFmt = f"{self.endian}H"
|
||||||
self.tagFormat = self.endian + "HHL"
|
self.tagFormat = f"{self.endian}HHL"
|
||||||
|
|
||||||
def skipIFDs(self):
|
def skipIFDs(self):
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -89,7 +89,7 @@ def check_codec(feature):
|
||||||
|
|
||||||
codec, lib = codecs[feature]
|
codec, lib = codecs[feature]
|
||||||
|
|
||||||
return codec + "_encoder" in dir(Image.core)
|
return f"{codec}_encoder" in dir(Image.core)
|
||||||
|
|
||||||
|
|
||||||
def version_codec(feature):
|
def version_codec(feature):
|
||||||
|
@ -105,7 +105,7 @@ def version_codec(feature):
|
||||||
|
|
||||||
codec, lib = codecs[feature]
|
codec, lib = codecs[feature]
|
||||||
|
|
||||||
version = getattr(Image.core, lib + "_version")
|
version = getattr(Image.core, f"{lib}_version")
|
||||||
|
|
||||||
if feature == "libtiff":
|
if feature == "libtiff":
|
||||||
return version.split("\n")[0].split("Version ")[1]
|
return version.split("\n")[0].split("Version ")[1]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user