Skip to content

Commit

Permalink
Merge pull request #6109 from radarhere/black
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Mar 4, 2022
2 parents d1124cd + 72b7ab5 commit 38f4660
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 98 deletions.
4 changes: 2 additions & 2 deletions .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"]
Expand All @@ -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$)
Expand Down
2 changes: 1 addition & 1 deletion Tests/32bit_segfault_check.py
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion Tests/check_large_memory.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Tests/check_large_memory_numpy.py
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_core_resources.py
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_libtiff.py
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions Tests/test_file_tiff_metadata.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_webp.py
Expand Up @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions Tests/test_image_access.py
Expand Up @@ -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)]:
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_image_putdata.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imagecms.py
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_imageqt.py
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_imagestat.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_map.py
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion Tests/test_pdfparser.py
Expand Up @@ -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>"
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/BmpImagePlugin.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/GimpPaletteFile.py
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImImagePlugin.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageStat.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImtImagePlugin.py
Expand Up @@ -22,7 +22,7 @@
#
# --------------------------------------------------------------------

field = re.compile(br"([a-z]*) ([^ \r\n]*)")
field = re.compile(rb"([a-z]*) ([^ \r\n]*)")


##
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/Jpeg2KImagePlugin.py
Expand Up @@ -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):
Expand Down

0 comments on commit 38f4660

Please sign in to comment.