diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 822fa43ca33..b546505656a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: f1d4e742c91dd5179d742b0db9293c4472b765f8 # frozen: 21.12b0 + rev: fc0be6eb1e2a96091e6f64009ee5e9081bf8b6c6 # frozen: 22.1.0 hooks: - id: black args: ["--target-version", "py37"] @@ -19,7 +19,7 @@ repos: - id: yesqa - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: 3592548bbd98528887eeed63486cf6c9bae00b98 # frozen: v1.1.10 + rev: ca52c4245639abd55c970e6bbbca95cab3de22d8 # frozen: v1.1.13 hooks: - id: remove-tabs exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.opt$) diff --git a/Tests/32bit_segfault_check.py b/Tests/32bit_segfault_check.py index e19cdf7a918..2ff7f908f6d 100755 --- a/Tests/32bit_segfault_check.py +++ b/Tests/32bit_segfault_check.py @@ -4,5 +4,5 @@ from PIL import Image -if sys.maxsize < 2 ** 32: +if sys.maxsize < 2**32: im = Image.new("L", (999999, 999999), 0) diff --git a/Tests/check_large_memory.py b/Tests/check_large_memory.py index c191ffc1eb8..d98f4a694ef 100644 --- a/Tests/check_large_memory.py +++ b/Tests/check_large_memory.py @@ -23,7 +23,7 @@ XDIM = 48000 -pytestmark = pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="requires 64-bit system") +pytestmark = pytest.mark.skipif(sys.maxsize <= 2**32, reason="requires 64-bit system") def _write_png(tmp_path, xdim, ydim): diff --git a/Tests/check_large_memory_numpy.py b/Tests/check_large_memory_numpy.py index 70ae6d230b8..24cb1f722bf 100644 --- a/Tests/check_large_memory_numpy.py +++ b/Tests/check_large_memory_numpy.py @@ -19,7 +19,7 @@ XDIM = 48000 -pytestmark = pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="requires 64-bit system") +pytestmark = pytest.mark.skipif(sys.maxsize <= 2**32, reason="requires 64-bit system") def _write_png(tmp_path, xdim, ydim): diff --git a/Tests/test_core_resources.py b/Tests/test_core_resources.py index 6c52d25a4aa..385192a3cdc 100644 --- a/Tests/test_core_resources.py +++ b/Tests/test_core_resources.py @@ -110,9 +110,9 @@ def test_set_blocks_max(self): with pytest.raises(ValueError): Image.core.set_blocks_max(-1) - if sys.maxsize < 2 ** 32: + if sys.maxsize < 2**32: with pytest.raises(ValueError): - Image.core.set_blocks_max(2 ** 29) + Image.core.set_blocks_max(2**29) @pytest.mark.skipif(is_pypy(), reason="Images not collected") def test_set_blocks_max_stats(self): diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 53ed2520ae0..a9337f4fc65 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -218,7 +218,7 @@ def test_additional_metadata(self, tmp_path): values = { 2: "test", 3: 1, - 4: 2 ** 20, + 4: 2**20, 5: TiffImagePlugin.IFDRational(100, 1), 12: 1.05, } @@ -1019,7 +1019,7 @@ def test_save_single_strip(self, tmp_path): im = hopper("RGB").resize((256, 256)) out = str(tmp_path / "temp.tif") - TiffImagePlugin.STRIP_SIZE = 2 ** 18 + TiffImagePlugin.STRIP_SIZE = 2**18 try: im.save(out, compression="tiff_adobe_deflate") diff --git a/Tests/test_file_tiff_metadata.py b/Tests/test_file_tiff_metadata.py index 2213af5aadf..0562955169f 100644 --- a/Tests/test_file_tiff_metadata.py +++ b/Tests/test_file_tiff_metadata.py @@ -258,7 +258,7 @@ def test_ifd_unsigned_rational(tmp_path): im = hopper() info = TiffImagePlugin.ImageFileDirectory_v2() - max_long = 2 ** 32 - 1 + max_long = 2**32 - 1 # 4 bytes unsigned long numerator = max_long @@ -290,8 +290,8 @@ def test_ifd_signed_rational(tmp_path): info = TiffImagePlugin.ImageFileDirectory_v2() # pair of 4 byte signed longs - numerator = 2 ** 31 - 1 - denominator = -(2 ** 31) + numerator = 2**31 - 1 + denominator = -(2**31) info[37380] = TiffImagePlugin.IFDRational(numerator, denominator) @@ -302,8 +302,8 @@ def test_ifd_signed_rational(tmp_path): assert numerator == reloaded.tag_v2[37380].numerator assert denominator == reloaded.tag_v2[37380].denominator - numerator = -(2 ** 31) - denominator = 2 ** 31 - 1 + numerator = -(2**31) + denominator = 2**31 - 1 info[37380] = TiffImagePlugin.IFDRational(numerator, denominator) @@ -315,7 +315,7 @@ def test_ifd_signed_rational(tmp_path): assert denominator == reloaded.tag_v2[37380].denominator # out of bounds of 4 byte signed long - numerator = -(2 ** 31) - 1 + numerator = -(2**31) - 1 denominator = 1 info[37380] = TiffImagePlugin.IFDRational(numerator, denominator) @@ -324,7 +324,7 @@ def test_ifd_signed_rational(tmp_path): im.save(out, tiffinfo=info, compression="raw") with Image.open(out) as reloaded: - assert 2 ** 31 - 1 == reloaded.tag_v2[37380].numerator + assert 2**31 - 1 == reloaded.tag_v2[37380].numerator assert -1 == reloaded.tag_v2[37380].denominator diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 55897f1eb5a..0511193782c 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -128,7 +128,7 @@ def test_write_unsupported_mode_P(self, tmp_path): self._roundtrip(tmp_path, "P", 50.0) - @pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="Requires 64-bit system") + @pytest.mark.skipif(sys.maxsize <= 2**32, reason="Requires 64-bit system") def test_write_encoding_error_message(self, tmp_path): temp_file = str(tmp_path / "temp.webp") im = Image.new("RGB", (15000, 15000)) diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py index 7b30369793c..97321143d7e 100644 --- a/Tests/test_image_access.py +++ b/Tests/test_image_access.py @@ -205,10 +205,10 @@ def test_signedness(self): # see https://github.com/python-pillow/Pillow/issues/452 # pixelaccess is using signed int* instead of uint* for mode in ("I;16", "I;16B"): - self.check(mode, 2 ** 15 - 1) - self.check(mode, 2 ** 15) - self.check(mode, 2 ** 15 + 1) - self.check(mode, 2 ** 16 - 1) + self.check(mode, 2**15 - 1) + self.check(mode, 2**15) + self.check(mode, 2**15 + 1) + self.check(mode, 2**16 - 1) def test_p_putpixel_rgb_rgba(self): for color in [(255, 0, 0), (255, 0, 0, 255)]: @@ -386,7 +386,7 @@ def test_putpixel_type_error2(self, mode): def test_putpixel_overflow_error(self, mode): im = hopper(mode) with pytest.raises(OverflowError): - im.putpixel((0, 0), 2 ** 80) + im.putpixel((0, 0), 2**80) def test_putpixel_unrecognized_mode(self): im = hopper("BGR;15") diff --git a/Tests/test_image_putdata.py b/Tests/test_image_putdata.py index 7e4bbaaec61..3d60e52a294 100644 --- a/Tests/test_image_putdata.py +++ b/Tests/test_image_putdata.py @@ -38,7 +38,7 @@ def put(value): assert put(0xFFFFFFFF) == (255, 255, 255, 255) assert put(-1) == (255, 255, 255, 255) assert put(-1) == (255, 255, 255, 255) - if sys.maxsize > 2 ** 32: + if sys.maxsize > 2**32: assert put(sys.maxsize) == (255, 255, 255, 255) else: assert put(sys.maxsize) == (255, 255, 255, 127) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index e0093739cc5..66a72a90eb2 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -303,7 +303,7 @@ def test_extended_information(): def assert_truncated_tuple_equal(tup1, tup2, digits=10): # Helper function to reduce precision of tuples of floats # recursively and then check equality. - power = 10 ** digits + power = 10**digits def truncate_tuple(tuple_or_float): return tuple( diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py index 93090793970..a42240d49bf 100644 --- a/Tests/test_imageqt.py +++ b/Tests/test_imageqt.py @@ -32,10 +32,10 @@ def test_rgb(): def checkrgb(r, g, b): val = ImageQt.rgb(r, g, b) - val = val % 2 ** 24 # drop the alpha + val = val % 2**24 # drop the alpha assert val >> 16 == r - assert ((val >> 8) % 2 ** 8) == g - assert val % 2 ** 8 == b + assert ((val >> 8) % 2**8) == g + assert val % 2**8 == b checkrgb(0, 0, 0) checkrgb(255, 0, 0) diff --git a/Tests/test_imagestat.py b/Tests/test_imagestat.py index 9474ff6f9ba..5717fe15036 100644 --- a/Tests/test_imagestat.py +++ b/Tests/test_imagestat.py @@ -51,8 +51,8 @@ def test_constant(): st = ImageStat.Stat(im) assert st.extrema[0] == (128, 128) - assert st.sum[0] == 128 ** 3 - assert st.sum2[0] == 128 ** 4 + assert st.sum[0] == 128**3 + assert st.sum2[0] == 128**4 assert st.mean[0] == 128 assert st.median[0] == 128 assert st.rms[0] == 128 diff --git a/Tests/test_map.py b/Tests/test_map.py index 42f3447ebfd..d816bddaf3d 100644 --- a/Tests/test_map.py +++ b/Tests/test_map.py @@ -36,7 +36,7 @@ def test_tobytes(): Image.MAX_IMAGE_PIXELS = max_pixels -@pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="Requires 64-bit system") +@pytest.mark.skipif(sys.maxsize <= 2**32, reason="Requires 64-bit system") def test_ysize(): numpy = pytest.importorskip("numpy", reason="NumPy not installed") diff --git a/Tests/test_pdfparser.py b/Tests/test_pdfparser.py index 2d428e95fce..ea9b33dfc91 100644 --- a/Tests/test_pdfparser.py +++ b/Tests/test_pdfparser.py @@ -115,6 +115,6 @@ def test_pdf_repr(): assert pdf_repr(True) == b"true" assert pdf_repr(False) == b"false" assert pdf_repr(None) == b"null" - assert pdf_repr(b"a)/b\\(c") == br"(a\)/b\\\(c)" + assert pdf_repr(b"a)/b\\(c") == rb"(a\)/b\\\(c)" assert pdf_repr([123, True, {"a": PdfName(b"b")}]) == b"[ 123 true <<\n/a /b\n>> ]" assert pdf_repr(PdfBinary(b"\x90\x1F\xA0")) == b"<901FA0>" diff --git a/setup.py b/setup.py index 23d91a5f24d..3468b260de3 100755 --- a/setup.py +++ b/setup.py @@ -167,7 +167,7 @@ def _find_library_dirs_ldconfig(): # Assuming GLIBC's ldconfig (with option -p) # Alpine Linux uses musl that can't print cache args = ["/sbin/ldconfig", "-p"] - expr = fr".*\({abi_type}.*\) => (.*)" + expr = rf".*\({abi_type}.*\) => (.*)" env = dict(os.environ) env["LC_ALL"] = "C" env["LANG"] = "C" diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index 7a7ad386c6f..72e40b05f66 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -102,7 +102,7 @@ def _bitmap(self, header=0, offset=0): file_info["height"] = ( i32(header_data, 4) if not file_info["y_flip"] - else 2 ** 32 - i32(header_data, 4) + else 2**32 - i32(header_data, 4) ) file_info["planes"] = i16(header_data, 8) file_info["bits"] = i16(header_data, 10) @@ -322,7 +322,7 @@ def _save(im, fp, filename, bitmap_header=True): if bitmap_header: offset = 14 + header + colors * 4 file_size = offset + image - if file_size > 2 ** 32 - 1: + if file_size > 2**32 - 1: raise ValueError("File size is too large for the BMP format") fp.write( b"BM" # file type (magic) diff --git a/src/PIL/GimpPaletteFile.py b/src/PIL/GimpPaletteFile.py index 10fd3ad8174..4d7cfbabab5 100644 --- a/src/PIL/GimpPaletteFile.py +++ b/src/PIL/GimpPaletteFile.py @@ -38,7 +38,7 @@ def __init__(self, fp): break # skip fields and comment lines - if re.match(br"\w+:|#", s): + if re.match(rb"\w+:|#", s): continue if len(s) > 100: raise SyntaxError("bad palette file") diff --git a/src/PIL/ImImagePlugin.py b/src/PIL/ImImagePlugin.py index 1dfc808c402..f7e690b355d 100644 --- a/src/PIL/ImImagePlugin.py +++ b/src/PIL/ImImagePlugin.py @@ -100,7 +100,7 @@ # -------------------------------------------------------------------- # Read IM directory -split = re.compile(br"^([A-Za-z][^:]*):[ \t]*(.*)[ \t]*$") +split = re.compile(rb"^([A-Za-z][^:]*):[ \t]*(.*)[ \t]*$") def number(s): diff --git a/src/PIL/ImageStat.py b/src/PIL/ImageStat.py index 50bafc97294..ef4a1d63318 100644 --- a/src/PIL/ImageStat.py +++ b/src/PIL/ImageStat.py @@ -91,7 +91,7 @@ def _getsum2(self): for i in range(0, len(self.h), 256): sum2 = 0.0 for j in range(256): - sum2 += (j ** 2) * float(self.h[i + j]) + sum2 += (j**2) * float(self.h[i + j]) v.append(sum2) return v diff --git a/src/PIL/ImtImagePlugin.py b/src/PIL/ImtImagePlugin.py index 21ffd747584..5790acdaf52 100644 --- a/src/PIL/ImtImagePlugin.py +++ b/src/PIL/ImtImagePlugin.py @@ -22,7 +22,7 @@ # # -------------------------------------------------------------------- -field = re.compile(br"([a-z]*) ([^ \r\n]*)") +field = re.compile(rb"([a-z]*) ([^ \r\n]*)") ## diff --git a/src/PIL/Jpeg2KImagePlugin.py b/src/PIL/Jpeg2KImagePlugin.py index cc7980278b3..4f4ee8f55b1 100644 --- a/src/PIL/Jpeg2KImagePlugin.py +++ b/src/PIL/Jpeg2KImagePlugin.py @@ -132,7 +132,7 @@ def _res_to_dpi(num, denom, exp): calculated as (num / denom) * 10^exp and stored in dots per meter, to floating-point dots per inch.""" if denom != 0: - return (254 * num * (10 ** exp)) / (10000 * denom) + return (254 * num * (10**exp)) / (10000 * denom) def _parse_jp2_header(fp): diff --git a/src/PIL/PdfParser.py b/src/PIL/PdfParser.py index 6ac9c7a7c67..9aa0fd6fa7f 100644 --- a/src/PIL/PdfParser.py +++ b/src/PIL/PdfParser.py @@ -576,42 +576,42 @@ def next_object_id(self, offset=None): self.xref_table[reference.object_id] = (offset, 0) return reference - delimiter = br"[][()<>{}/%]" - delimiter_or_ws = br"[][()<>{}/%\000\011\012\014\015\040]" - whitespace = br"[\000\011\012\014\015\040]" - whitespace_or_hex = br"[\000\011\012\014\015\0400-9a-fA-F]" + delimiter = rb"[][()<>{}/%]" + delimiter_or_ws = rb"[][()<>{}/%\000\011\012\014\015\040]" + whitespace = rb"[\000\011\012\014\015\040]" + whitespace_or_hex = rb"[\000\011\012\014\015\0400-9a-fA-F]" whitespace_optional = whitespace + b"*" whitespace_mandatory = whitespace + b"+" # No "\012" aka "\n" or "\015" aka "\r": - whitespace_optional_no_nl = br"[\000\011\014\040]*" - newline_only = br"[\r\n]+" + whitespace_optional_no_nl = rb"[\000\011\014\040]*" + newline_only = rb"[\r\n]+" newline = whitespace_optional_no_nl + newline_only + whitespace_optional_no_nl re_trailer_end = re.compile( whitespace_mandatory - + br"trailer" + + rb"trailer" + whitespace_optional - + br"\<\<(.*\>\>)" + + rb"\<\<(.*\>\>)" + newline - + br"startxref" + + rb"startxref" + newline - + br"([0-9]+)" + + rb"([0-9]+)" + newline - + br"%%EOF" + + rb"%%EOF" + whitespace_optional - + br"$", + + rb"$", re.DOTALL, ) re_trailer_prev = re.compile( whitespace_optional - + br"trailer" + + rb"trailer" + whitespace_optional - + br"\<\<(.*?\>\>)" + + rb"\<\<(.*?\>\>)" + newline - + br"startxref" + + rb"startxref" + newline - + br"([0-9]+)" + + rb"([0-9]+)" + newline - + br"%%EOF" + + rb"%%EOF" + whitespace_optional, re.DOTALL, ) @@ -655,12 +655,12 @@ def read_prev_trailer(self, xref_section_offset): re_whitespace_optional = re.compile(whitespace_optional) re_name = re.compile( whitespace_optional - + br"/([!-$&'*-.0-;=?-Z\\^-z|~]+)(?=" + + rb"/([!-$&'*-.0-;=?-Z\\^-z|~]+)(?=" + delimiter_or_ws - + br")" + + rb")" ) - re_dict_start = re.compile(whitespace_optional + br"\<\<") - re_dict_end = re.compile(whitespace_optional + br"\>\>" + whitespace_optional) + re_dict_start = re.compile(whitespace_optional + rb"\<\<") + re_dict_end = re.compile(whitespace_optional + rb"\>\>" + whitespace_optional) @classmethod def interpret_trailer(cls, trailer_data): @@ -689,7 +689,7 @@ def interpret_trailer(cls, trailer_data): ) return trailer - re_hashes_in_name = re.compile(br"([^#]*)(#([0-9a-fA-F]{2}))?") + re_hashes_in_name = re.compile(rb"([^#]*)(#([0-9a-fA-F]{2}))?") @classmethod def interpret_name(cls, raw, as_text=False): @@ -704,53 +704,53 @@ def interpret_name(cls, raw, as_text=False): else: return bytes(name) - re_null = re.compile(whitespace_optional + br"null(?=" + delimiter_or_ws + br")") - re_true = re.compile(whitespace_optional + br"true(?=" + delimiter_or_ws + br")") - re_false = re.compile(whitespace_optional + br"false(?=" + delimiter_or_ws + br")") + re_null = re.compile(whitespace_optional + rb"null(?=" + delimiter_or_ws + rb")") + re_true = re.compile(whitespace_optional + rb"true(?=" + delimiter_or_ws + rb")") + re_false = re.compile(whitespace_optional + rb"false(?=" + delimiter_or_ws + rb")") re_int = re.compile( - whitespace_optional + br"([-+]?[0-9]+)(?=" + delimiter_or_ws + br")" + whitespace_optional + rb"([-+]?[0-9]+)(?=" + delimiter_or_ws + rb")" ) re_real = re.compile( whitespace_optional - + br"([-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+))(?=" + + rb"([-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+))(?=" + delimiter_or_ws - + br")" + + rb")" ) - re_array_start = re.compile(whitespace_optional + br"\[") - re_array_end = re.compile(whitespace_optional + br"]") + re_array_start = re.compile(whitespace_optional + rb"\[") + re_array_end = re.compile(whitespace_optional + rb"]") re_string_hex = re.compile( - whitespace_optional + br"\<(" + whitespace_or_hex + br"*)\>" + whitespace_optional + rb"\<(" + whitespace_or_hex + rb"*)\>" ) - re_string_lit = re.compile(whitespace_optional + br"\(") + re_string_lit = re.compile(whitespace_optional + rb"\(") re_indirect_reference = re.compile( whitespace_optional - + br"([-+]?[0-9]+)" + + rb"([-+]?[0-9]+)" + whitespace_mandatory - + br"([-+]?[0-9]+)" + + rb"([-+]?[0-9]+)" + whitespace_mandatory - + br"R(?=" + + rb"R(?=" + delimiter_or_ws - + br")" + + rb")" ) re_indirect_def_start = re.compile( whitespace_optional - + br"([-+]?[0-9]+)" + + rb"([-+]?[0-9]+)" + whitespace_mandatory - + br"([-+]?[0-9]+)" + + rb"([-+]?[0-9]+)" + whitespace_mandatory - + br"obj(?=" + + rb"obj(?=" + delimiter_or_ws - + br")" + + rb")" ) re_indirect_def_end = re.compile( - whitespace_optional + br"endobj(?=" + delimiter_or_ws + br")" + whitespace_optional + rb"endobj(?=" + delimiter_or_ws + rb")" ) re_comment = re.compile( - br"(" + whitespace_optional + br"%[^\r\n]*" + newline + br")*" + rb"(" + whitespace_optional + rb"%[^\r\n]*" + newline + rb")*" ) - re_stream_start = re.compile(whitespace_optional + br"stream\r?\n") + re_stream_start = re.compile(whitespace_optional + rb"stream\r?\n") re_stream_end = re.compile( - whitespace_optional + br"endstream(?=" + delimiter_or_ws + br")" + whitespace_optional + rb"endstream(?=" + delimiter_or_ws + rb")" ) @classmethod @@ -876,7 +876,7 @@ def get_value(cls, data, offset, expect_indirect=None, max_nesting=-1): raise PdfFormatError("unrecognized object: " + repr(data[offset : offset + 32])) re_lit_str_token = re.compile( - br"(\\[nrtbf()\\])|(\\[0-9]{1,3})|(\\(\r\n|\r|\n))|(\r\n|\r|\n)|(\()|(\))" + rb"(\\[nrtbf()\\])|(\\[0-9]{1,3})|(\\(\r\n|\r|\n))|(\r\n|\r|\n)|(\()|(\))" ) escaped_chars = { b"n": b"\n", @@ -922,16 +922,16 @@ def get_literal_string(cls, data, offset): offset = m.end() raise PdfFormatError("unfinished literal string") - re_xref_section_start = re.compile(whitespace_optional + br"xref" + newline) + re_xref_section_start = re.compile(whitespace_optional + rb"xref" + newline) re_xref_subsection_start = re.compile( whitespace_optional - + br"([0-9]+)" + + rb"([0-9]+)" + whitespace_mandatory - + br"([0-9]+)" + + rb"([0-9]+)" + whitespace_optional + newline_only ) - re_xref_entry = re.compile(br"([0-9]{10}) ([0-9]{5}) ([fn])( \r| \n|\r\n)") + re_xref_entry = re.compile(rb"([0-9]{10}) ([0-9]{5}) ([fn])( \r| \n|\r\n)") def read_xref_table(self, xref_section_offset): subsection_found = False diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index cd0a3e0e0da..53525e22e78 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -48,7 +48,7 @@ logger = logging.getLogger(__name__) -is_cid = re.compile(br"\w\w\w\w").match +is_cid = re.compile(rb"\w\w\w\w").match _MAGIC = b"\211PNG\r\n\032\n" diff --git a/src/PIL/PpmImagePlugin.py b/src/PIL/PpmImagePlugin.py index 9d32927d4ca..9e962cac88b 100644 --- a/src/PIL/PpmImagePlugin.py +++ b/src/PIL/PpmImagePlugin.py @@ -115,7 +115,7 @@ def _open(self): if maxval > 255: if not mode == "L": raise ValueError(f"Too many colors for band: {token}") - if maxval < 2 ** 16: + if maxval < 2**16: self.mode = "I" rawmode = "I;16B" else: @@ -136,7 +136,7 @@ def _save(im, fp, filename): elif im.mode == "L": rawmode, head = "L", b"P5" elif im.mode == "I": - if im.getextrema()[1] < 2 ** 16: + if im.getextrema()[1] < 2**16: rawmode, head = "I;16B", b"P5" else: rawmode, head = "I;32B", b"P5" diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 35ff1c1bbf7..5245e26c645 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -577,9 +577,9 @@ def _setitem(self, tag, value, legacy_api): else TiffTags.SIGNED_RATIONAL ) elif all(isinstance(v, int) for v in values): - if all(0 <= v < 2 ** 16 for v in values): + if all(0 <= v < 2**16 for v in values): self.tagtype[tag] = TiffTags.SHORT - elif all(-(2 ** 15) < v < 2 ** 15 for v in values): + elif all(-(2**15) < v < 2**15 for v in values): self.tagtype[tag] = TiffTags.SIGNED_SHORT else: self.tagtype[tag] = ( @@ -734,7 +734,7 @@ def combine(a, b): @_register_writer(5) def write_rational(self, *values): return b"".join( - self._pack("2L", *_limit_rational(frac, 2 ** 32 - 1)) for frac in values + self._pack("2L", *_limit_rational(frac, 2**32 - 1)) for frac in values ) @_register_loader(7, 1) @@ -757,7 +757,7 @@ def combine(a, b): @_register_writer(10) def write_signed_rational(self, *values): return b"".join( - self._pack("2l", *_limit_signed_rational(frac, 2 ** 31 - 1, -(2 ** 31))) + self._pack("2l", *_limit_signed_rational(frac, 2**31 - 1, -(2**31))) for frac in values ) @@ -1670,7 +1670,7 @@ def _save(im, fp, filename): strip_byte_counts = 1 if stride == 0 else stride * rows_per_strip strips_per_image = (im.size[1] + rows_per_strip - 1) // rows_per_strip ifd[ROWSPERSTRIP] = rows_per_strip - if strip_byte_counts >= 2 ** 16: + if strip_byte_counts >= 2**16: ifd.tagtype[STRIPBYTECOUNTS] = TiffTags.LONG ifd[STRIPBYTECOUNTS] = (strip_byte_counts,) * (strips_per_image - 1) + ( stride * im.size[1] - strip_byte_counts * (strips_per_image - 1), diff --git a/src/PIL/XbmImagePlugin.py b/src/PIL/XbmImagePlugin.py index 644cfb39bc6..f7e49448560 100644 --- a/src/PIL/XbmImagePlugin.py +++ b/src/PIL/XbmImagePlugin.py @@ -25,7 +25,7 @@ # XBM header xbm_head = re.compile( - br"\s*#define[ \t]+.*_width[ \t]+(?P[0-9]+)[\r\n]+" + rb"\s*#define[ \t]+.*_width[ \t]+(?P[0-9]+)[\r\n]+" b"#define[ \t]+.*_height[ \t]+(?P[0-9]+)[\r\n]+" b"(?P" b"#define[ \t]+[^_]*_x_hot[ \t]+(?P[0-9]+)[\r\n]+" diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index 3ff1aeca0ca..31a3fbab77b 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -464,7 +464,7 @@ def build_dep_all(): if dep_name in disabled: continue script = build_dep(dep_name) - lines.append(fr'cmd.exe /c "{{build_dir}}\{script}"') + lines.append(rf'cmd.exe /c "{{build_dir}}\{script}"') lines.append("if errorlevel 1 echo Build failed! && exit /B 1") lines.append("@echo All Pillow dependencies built successfully!") write_script("build_dep_all.cmd", lines)