mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +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: >
|
||||
gcc-g++
|
||||
ghostscript
|
||||
git
|
||||
ImageMagick
|
||||
jpeg
|
||||
libfreetype-devel
|
||||
|
@ -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:
|
||||
|
|
3
.github/workflows/test-docker.yml
vendored
3
.github/workflows/test-docker.yml
vendored
|
@ -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:
|
||||
|
|
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
|
||||
|
||||
- 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
.github/workflows/test-windows.yml
vendored
3
.github/workflows/test-windows.yml
vendored
|
@ -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:
|
||||
|
|
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
|
@ -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:
|
||||
|
|
|
@ -271,16 +271,16 @@ class D3DFMT(IntEnum):
|
|||
module = sys.modules[__name__]
|
||||
for item in DDSD:
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
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_RGB = DDPF.RGB
|
||||
|
|
|
@ -196,7 +196,7 @@ class ImImageFile(ImageFile.ImageFile):
|
|||
n += 1
|
||||
|
||||
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)
|
||||
|
||||
if not n:
|
||||
|
|
|
@ -414,7 +414,7 @@ def _getdecoder(mode, decoder_name, args, extra=()):
|
|||
|
||||
try:
|
||||
# get decoder
|
||||
decoder = getattr(core, decoder_name + "_decoder")
|
||||
decoder = getattr(core, f"{decoder_name}_decoder")
|
||||
except AttributeError as e:
|
||||
msg = f"decoder {decoder_name} not available"
|
||||
raise OSError(msg) from e
|
||||
|
@ -437,7 +437,7 @@ def _getencoder(mode, encoder_name, args, extra=()):
|
|||
|
||||
try:
|
||||
# get encoder
|
||||
encoder = getattr(core, encoder_name + "_encoder")
|
||||
encoder = getattr(core, f"{encoder_name}_encoder")
|
||||
except AttributeError as e:
|
||||
msg = f"encoder {encoder_name} not available"
|
||||
raise OSError(msg) from e
|
||||
|
@ -637,7 +637,7 @@ class Image:
|
|||
) -> str:
|
||||
suffix = ""
|
||||
if format:
|
||||
suffix = "." + format
|
||||
suffix = f".{format}"
|
||||
|
||||
if not file:
|
||||
f, filename = tempfile.mkstemp(suffix)
|
||||
|
@ -2216,7 +2216,7 @@ class Image:
|
|||
(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)
|
||||
|
||||
if reducing_gap is not None and reducing_gap < 1.0:
|
||||
|
@ -2861,7 +2861,7 @@ class Image:
|
|||
(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)
|
||||
|
||||
image.load()
|
||||
|
@ -3259,8 +3259,8 @@ _fromarray_typemap = {
|
|||
((1, 1, 3), "|u1"): ("RGB", "RGB"),
|
||||
((1, 1, 4), "|u1"): ("RGBA", "RGBA"),
|
||||
# shortcuts:
|
||||
((1, 1), _ENDIAN + "i4"): ("I", "I"),
|
||||
((1, 1), _ENDIAN + "f4"): ("F", "F"),
|
||||
((1, 1), f"{_ENDIAN}i4"): ("I", "I"),
|
||||
((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)
|
||||
im_1.load()
|
||||
try:
|
||||
op = getattr(_imagingmath, op + "_" + im_1.mode)
|
||||
op = getattr(_imagingmath, f"{op}_{im_1.mode}")
|
||||
except AttributeError as e:
|
||||
msg = f"bad operand type for '{op}'"
|
||||
raise TypeError(msg) from e
|
||||
|
@ -89,7 +89,7 @@ class _Operand:
|
|||
im_1.load()
|
||||
im_2.load()
|
||||
try:
|
||||
op = getattr(_imagingmath, op + "_" + im_1.mode)
|
||||
op = getattr(_imagingmath, f"{op}_{im_1.mode}")
|
||||
except AttributeError as e:
|
||||
msg = f"bad operand type for '{op}'"
|
||||
raise TypeError(msg) from e
|
||||
|
|
|
@ -44,8 +44,8 @@ def getmode(mode: str) -> ModeDescriptor:
|
|||
# Bits need to be extended to bytes
|
||||
"1": ("L", "L", ("1",), "|b1"),
|
||||
"L": ("L", "L", ("L",), "|u1"),
|
||||
"I": ("L", "I", ("I",), endian + "i4"),
|
||||
"F": ("L", "F", ("F",), endian + "f4"),
|
||||
"I": ("L", "I", ("I",), f"{endian}i4"),
|
||||
"F": ("L", "F", ("F",), f"{endian}f4"),
|
||||
"P": ("P", "L", ("P",), "|u1"),
|
||||
"RGB": ("RGB", "L", ("R", "G", "B"), "|u1"),
|
||||
"RGBX": ("RGB", "L", ("R", "G", "B", "X"), "|u1"),
|
||||
|
@ -78,8 +78,8 @@ def getmode(mode: str) -> ModeDescriptor:
|
|||
"I;16LS": "<i2",
|
||||
"I;16B": ">u2",
|
||||
"I;16BS": ">i2",
|
||||
"I;16N": endian + "u2",
|
||||
"I;16NS": endian + "i2",
|
||||
"I;16N": f"{endian}u2",
|
||||
"I;16NS": f"{endian}i2",
|
||||
"I;32": "<u4",
|
||||
"I;32B": ">u4",
|
||||
"I;32L": "<u4",
|
||||
|
|
|
@ -84,7 +84,7 @@ class LutBuilder:
|
|||
],
|
||||
}
|
||||
if op_name not in known_patterns:
|
||||
msg = "Unknown pattern " + op_name + "!"
|
||||
msg = f"Unknown pattern {op_name}!"
|
||||
raise Exception(msg)
|
||||
|
||||
self.patterns = known_patterns[op_name]
|
||||
|
|
|
@ -196,7 +196,7 @@ class Window:
|
|||
)
|
||||
|
||||
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):
|
||||
pass
|
||||
|
|
|
@ -142,7 +142,7 @@ def _save(im, fp, filename):
|
|||
|
||||
# we ignore the palette here
|
||||
im.mode = "P"
|
||||
rawmode = "P;" + str(bpp)
|
||||
rawmode = f"P;{bpp}"
|
||||
version = 1
|
||||
|
||||
elif im.mode == "1":
|
||||
|
|
|
@ -144,9 +144,7 @@ class XrefTable:
|
|||
elif key in self.deleted_entries:
|
||||
generation = self.deleted_entries[key]
|
||||
else:
|
||||
msg = (
|
||||
"object ID " + str(key) + " cannot be deleted because it doesn't exist"
|
||||
)
|
||||
msg = f"object ID {key} cannot be deleted because it doesn't exist"
|
||||
raise IndexError(msg)
|
||||
|
||||
def __contains__(self, key):
|
||||
|
@ -225,7 +223,7 @@ class PdfName:
|
|||
return hash(self.name)
|
||||
|
||||
def __repr__(self):
|
||||
return f"PdfName({repr(self.name)})"
|
||||
return f"{self.__class__.__name__}({repr(self.name)})"
|
||||
|
||||
@classmethod
|
||||
def from_pdf_stream(cls, data):
|
||||
|
@ -884,7 +882,7 @@ class PdfParser:
|
|||
if m:
|
||||
return cls.get_literal_string(data, m.end())
|
||||
# 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)
|
||||
|
||||
re_lit_str_token = re.compile(
|
||||
|
|
|
@ -189,7 +189,7 @@ class ChunkStream:
|
|||
"""Call the appropriate chunk handler"""
|
||||
|
||||
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):
|
||||
"""Read and verify checksum"""
|
||||
|
|
|
@ -218,7 +218,7 @@ def loadImageSeries(filelist=None):
|
|||
im = im.convert2byte()
|
||||
except Exception:
|
||||
if not isSpiderImage(img):
|
||||
print(img + " is not a Spider image file")
|
||||
print(f"{img} is not a Spider image file")
|
||||
continue
|
||||
im.info["filename"] = img
|
||||
imglist.append(im)
|
||||
|
@ -299,10 +299,10 @@ if __name__ == "__main__":
|
|||
sys.exit()
|
||||
|
||||
with Image.open(filename) as im:
|
||||
print("image: " + str(im))
|
||||
print("format: " + str(im.format))
|
||||
print("size: " + str(im.size))
|
||||
print("mode: " + str(im.mode))
|
||||
print(f"image: {im}")
|
||||
print(f"format: {im.format}")
|
||||
print(f"size: {im.size}")
|
||||
print(f"mode: {im.mode}")
|
||||
print("max, min: ", end=" ")
|
||||
print(im.getextrema())
|
||||
|
||||
|
|
|
@ -469,7 +469,7 @@ def _register_basic(idx_fmt_name):
|
|||
|
||||
idx, fmt, name = idx_fmt_name
|
||||
TYPES[idx] = name
|
||||
size = struct.calcsize("=" + fmt)
|
||||
size = struct.calcsize(f"={fmt}")
|
||||
_load_dispatch[idx] = ( # noqa: F821
|
||||
size,
|
||||
lambda self, data, legacy_api=True: (
|
||||
|
@ -987,8 +987,8 @@ ImageFileDirectory_v2._load_dispatch = _load_dispatch
|
|||
ImageFileDirectory_v2._write_dispatch = _write_dispatch
|
||||
for idx, name in TYPES.items():
|
||||
name = name.replace(" ", "_")
|
||||
setattr(ImageFileDirectory_v2, "load_" + name, _load_dispatch[idx][1])
|
||||
setattr(ImageFileDirectory_v2, "write_" + name, _write_dispatch[idx])
|
||||
setattr(ImageFileDirectory_v2, f"load_{name}", _load_dispatch[idx][1])
|
||||
setattr(ImageFileDirectory_v2, f"write_{name}", _write_dispatch[idx])
|
||||
del _load_dispatch, _write_dispatch, idx, name
|
||||
|
||||
|
||||
|
@ -2025,9 +2025,9 @@ class AppendingTiffWriter:
|
|||
|
||||
def setEndian(self, endian):
|
||||
self.endian = endian
|
||||
self.longFmt = self.endian + "L"
|
||||
self.shortFmt = self.endian + "H"
|
||||
self.tagFormat = self.endian + "HHL"
|
||||
self.longFmt = f"{self.endian}L"
|
||||
self.shortFmt = f"{self.endian}H"
|
||||
self.tagFormat = f"{self.endian}HHL"
|
||||
|
||||
def skipIFDs(self):
|
||||
while True:
|
||||
|
|
|
@ -89,7 +89,7 @@ def check_codec(feature):
|
|||
|
||||
codec, lib = codecs[feature]
|
||||
|
||||
return codec + "_encoder" in dir(Image.core)
|
||||
return f"{codec}_encoder" in dir(Image.core)
|
||||
|
||||
|
||||
def version_codec(feature):
|
||||
|
@ -105,7 +105,7 @@ def version_codec(feature):
|
|||
|
||||
codec, lib = codecs[feature]
|
||||
|
||||
version = getattr(Image.core, lib + "_version")
|
||||
version = getattr(Image.core, f"{lib}_version")
|
||||
|
||||
if feature == "libtiff":
|
||||
return version.split("\n")[0].split("Version ")[1]
|
||||
|
|
Loading…
Reference in New Issue
Block a user