Skip to content

Commit a986fed

Browse files
authored
Format code with Black (#3733)
Format code with Black
2 parents 92dc8f4 + cab7231 commit a986fed

91 files changed

Lines changed: 3265 additions & 2717 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-e .
33
alabaster
44
Babel
5+
black; python_version >= '3.6'
56
check-manifest
67
cov-core
78
coverage

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
test=pytest
33

44
[flake8]
5+
extend-ignore = E203, W503
56
max-line-length = 88

src/PIL/BdfFontFile.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@
3232
"O": "Oblique",
3333
"RI": "Reverse Italic",
3434
"RO": "Reverse Oblique",
35-
"OT": "Other"
35+
"OT": "Other",
3636
}
3737

38-
bdf_spacing = {
39-
"P": "Proportional",
40-
"M": "Monospaced",
41-
"C": "Cell"
42-
}
38+
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}
4339

4440

4541
def bdf_char(f):
@@ -50,7 +46,7 @@ def bdf_char(f):
5046
return None
5147
if s[:9] == b"STARTCHAR":
5248
break
53-
id = s[9:].strip().decode('ascii')
49+
id = s[9:].strip().decode("ascii")
5450

5551
# load symbol properties
5652
props = {}
@@ -59,7 +55,7 @@ def bdf_char(f):
5955
if not s or s[:6] == b"BITMAP":
6056
break
6157
i = s.find(b" ")
62-
props[s[:i].decode('ascii')] = s[i+1:-1].decode('ascii')
58+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
6359

6460
# load bitmap
6561
bitmap = []
@@ -73,7 +69,7 @@ def bdf_char(f):
7369
[x, y, l, d] = [int(p) for p in props["BBX"].split()]
7470
[dx, dy] = [int(p) for p in props["DWIDTH"].split()]
7571

76-
bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y)
72+
bbox = (dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y)
7773

7874
try:
7975
im = Image.frombytes("1", (x, y), bitmap, "hex", "1")
@@ -87,8 +83,8 @@ def bdf_char(f):
8783
##
8884
# Font file plugin for the X11 BDF format.
8985

90-
class BdfFontFile(FontFile.FontFile):
9186

87+
class BdfFontFile(FontFile.FontFile):
9288
def __init__(self, fp):
9389

9490
FontFile.FontFile.__init__(self)
@@ -105,10 +101,10 @@ def __init__(self, fp):
105101
if not s or s[:13] == b"ENDPROPERTIES":
106102
break
107103
i = s.find(b" ")
108-
props[s[:i].decode('ascii')] = s[i+1:-1].decode('ascii')
104+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
109105
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
110106
if s.find(b"LogicalFontDescription") < 0:
111-
comments.append(s[i+1:-1].decode('ascii'))
107+
comments.append(s[i + 1 : -1].decode("ascii"))
112108

113109
while True:
114110
c = bdf_char(fp)

src/PIL/BlpImagePlugin.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@
4747

4848

4949
def unpack_565(i):
50-
return (
51-
((i >> 11) & 0x1f) << 3,
52-
((i >> 5) & 0x3f) << 2,
53-
(i & 0x1f) << 3
54-
)
50+
return (((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3)
5551

5652

5753
def decode_dxt1(data, alpha=False):
@@ -119,7 +115,7 @@ def decode_dxt3(data):
119115

120116
for block in range(blocks):
121117
idx = block * 16
122-
block = data[idx:idx + 16]
118+
block = data[idx : idx + 16]
123119
# Decode next 16-byte block.
124120
bits = struct.unpack_from("<8B", block)
125121
color0, color1 = struct.unpack_from("<HH", block, 8)
@@ -139,7 +135,7 @@ def decode_dxt3(data):
139135
a >>= 4
140136
else:
141137
high = True
142-
a &= 0xf
138+
a &= 0xF
143139
a *= 17 # We get a value between 0 and 15
144140

145141
color_code = (code >> 2 * (4 * j + i)) & 0x03
@@ -172,14 +168,12 @@ def decode_dxt5(data):
172168

173169
for block in range(blocks):
174170
idx = block * 16
175-
block = data[idx:idx + 16]
171+
block = data[idx : idx + 16]
176172
# Decode next 16-byte block.
177173
a0, a1 = struct.unpack_from("<BB", block)
178174

179175
bits = struct.unpack_from("<6B", block, 2)
180-
alphacode1 = (
181-
bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
182-
)
176+
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
183177
alphacode2 = bits[0] | (bits[1] << 8)
184178

185179
color0, color1 = struct.unpack_from("<HH", block, 8)
@@ -242,6 +236,7 @@ class BlpImageFile(ImageFile.ImageFile):
242236
"""
243237
Blizzard Mipmap Format
244238
"""
239+
245240
format = "BLP"
246241
format_description = "Blizzard Mipmap Format"
247242

@@ -258,9 +253,7 @@ def _open(self):
258253
else:
259254
raise BLPFormatError("Bad BLP magic %r" % (self.magic))
260255

261-
self.tile = [
262-
(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))
263-
]
256+
self.tile = [(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))]
264257

265258
def _read_blp_header(self):
266259
self._blp_compression, = struct.unpack("<i", self.fp.read(4))
@@ -324,7 +317,6 @@ def _read_blp_header(self):
324317

325318

326319
class BLP1Decoder(_BLPBaseDecoder):
327-
328320
def _load(self):
329321
if self._blp_compression == BLP_FORMAT_JPEG:
330322
self._decode_jpeg_stream()
@@ -368,7 +360,6 @@ def _decode_jpeg_stream(self):
368360

369361

370362
class BLP2Decoder(_BLPBaseDecoder):
371-
372363
def _load(self):
373364
palette = self._read_palette()
374365

@@ -393,8 +384,7 @@ def _load(self):
393384
linesize = (self.size[0] + 3) // 4 * 8
394385
for yb in range((self.size[1] + 3) // 4):
395386
for d in decode_dxt1(
396-
self.fd.read(linesize),
397-
alpha=bool(self._blp_alpha_depth)
387+
self.fd.read(linesize), alpha=bool(self._blp_alpha_depth)
398388
):
399389
data += d
400390

@@ -410,18 +400,14 @@ def _load(self):
410400
for d in decode_dxt5(self.fd.read(linesize)):
411401
data += d
412402
else:
413-
raise BLPFormatError("Unsupported alpha encoding %r" % (
414-
self._blp_alpha_encoding
415-
))
403+
raise BLPFormatError(
404+
"Unsupported alpha encoding %r" % (self._blp_alpha_encoding)
405+
)
416406
else:
417-
raise BLPFormatError(
418-
"Unknown BLP encoding %r" % (self._blp_encoding)
419-
)
407+
raise BLPFormatError("Unknown BLP encoding %r" % (self._blp_encoding))
420408

421409
else:
422-
raise BLPFormatError(
423-
"Unknown BLP compression %r" % (self._blp_compression)
424-
)
410+
raise BLPFormatError("Unknown BLP compression %r" % (self._blp_compression))
425411

426412
self.set_as_raw(bytes(data))
427413

0 commit comments

Comments
 (0)