Skip to content

Commit 1a05d6c

Browse files
committed
PEP 7 style for if/else in C
Add also a newline for readability in normalize_encoding().
1 parent 65a5a47 commit 1a05d6c

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

Lib/encodings/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def normalize_encoding(encoding):
5454
"""
5555
if isinstance(encoding, bytes):
5656
encoding = str(encoding, "ascii")
57+
5758
chars = []
5859
punct = False
5960
for c in encoding:

Objects/stringlib/codecs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ STRINGLIB(utf8_encoder)(PyObject *unicode,
314314
else if (Py_UNICODE_IS_SURROGATE(ch)) {
315315
Py_ssize_t startpos, endpos, newpos;
316316
Py_ssize_t k;
317-
if (error_handler == _Py_ERROR_UNKNOWN)
317+
if (error_handler == _Py_ERROR_UNKNOWN) {
318318
error_handler = get_error_handler(errors);
319+
}
319320

320321
startpos = i-1;
321322
endpos = startpos+1;

Objects/unicodeobject.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,27 @@ typedef enum {
316316
static _Py_error_handler
317317
get_error_handler(const char *errors)
318318
{
319-
if (errors == NULL || strcmp(errors, "strict") == 0)
319+
if (errors == NULL || strcmp(errors, "strict") == 0) {
320320
return _Py_ERROR_STRICT;
321-
if (strcmp(errors, "surrogateescape") == 0)
321+
}
322+
if (strcmp(errors, "surrogateescape") == 0) {
322323
return _Py_ERROR_SURROGATEESCAPE;
323-
if (strcmp(errors, "replace") == 0)
324+
}
325+
if (strcmp(errors, "replace") == 0) {
324326
return _Py_ERROR_REPLACE;
325-
if (strcmp(errors, "ignore") == 0)
327+
}
328+
if (strcmp(errors, "ignore") == 0) {
326329
return _Py_ERROR_IGNORE;
327-
if (strcmp(errors, "backslashreplace") == 0)
330+
}
331+
if (strcmp(errors, "backslashreplace") == 0) {
328332
return _Py_ERROR_BACKSLASHREPLACE;
329-
if (strcmp(errors, "surrogatepass") == 0)
333+
}
334+
if (strcmp(errors, "surrogatepass") == 0) {
330335
return _Py_ERROR_SURROGATEPASS;
331-
if (strcmp(errors, "xmlcharrefreplace") == 0)
336+
}
337+
if (strcmp(errors, "xmlcharrefreplace") == 0) {
332338
return _Py_ERROR_XMLCHARREFREPLACE;
339+
}
333340
return _Py_ERROR_OTHER;
334341
}
335342

@@ -5636,36 +5643,45 @@ _PyUnicode_EncodeUTF16(PyObject *str,
56365643
if (kind == PyUnicode_4BYTE_KIND) {
56375644
const Py_UCS4 *in = (const Py_UCS4 *)data;
56385645
const Py_UCS4 *end = in + len;
5639-
while (in < end)
5640-
if (*in++ >= 0x10000)
5646+
while (in < end) {
5647+
if (*in++ >= 0x10000) {
56415648
pairs++;
5649+
}
5650+
}
56425651
}
5643-
if (len > PY_SSIZE_T_MAX / 2 - pairs - (byteorder == 0))
5652+
if (len > PY_SSIZE_T_MAX / 2 - pairs - (byteorder == 0)) {
56445653
return PyErr_NoMemory();
5654+
}
56455655
nsize = len + pairs + (byteorder == 0);
56465656
v = PyBytes_FromStringAndSize(NULL, nsize * 2);
5647-
if (v == NULL)
5657+
if (v == NULL) {
56485658
return NULL;
5659+
}
56495660

56505661
/* output buffer is 2-bytes aligned */
56515662
assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(v), 2));
56525663
out = (unsigned short *)PyBytes_AS_STRING(v);
5653-
if (byteorder == 0)
5664+
if (byteorder == 0) {
56545665
*out++ = 0xFEFF;
5655-
if (len == 0)
5666+
}
5667+
if (len == 0) {
56565668
goto done;
5669+
}
56575670

56585671
if (kind == PyUnicode_1BYTE_KIND) {
56595672
ucs1lib_utf16_encode((const Py_UCS1 *)data, len, &out, native_ordering);
56605673
goto done;
56615674
}
56625675

5663-
if (byteorder < 0)
5676+
if (byteorder < 0) {
56645677
encoding = "utf-16-le";
5665-
else if (byteorder > 0)
5678+
}
5679+
else if (byteorder > 0) {
56665680
encoding = "utf-16-be";
5667-
else
5681+
}
5682+
else {
56685683
encoding = "utf-16";
5684+
}
56695685

56705686
pos = 0;
56715687
while (pos < len) {

0 commit comments

Comments
 (0)