8000 Make else clauses in line with PEP 7 · python/cpython@85efc18 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85efc18

Browse files
committed
Make else clauses in line with PEP 7
1 parent 0962bbb commit 85efc18

File tree

4 files changed

+70
-35
lines changed

4 files changed

+70
-35
lines changed

Modules/_zstd/_zstdmodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ set_parameter_error(const _zstd_state* const state, int is_compress,
119119
list = cp_list;
120120
list_size = Py_ARRAY_LENGTH(cp_list);
121121
type = "compression";
122-
} else {
122+
}
123+
else {
123124
list = dp_list;
124125
list_size = Py_ARRAY_LENGTH(dp_list);
125126
type = "decompression";
@@ -144,7 +145,8 @@ set_parameter_error(const _zstd_state* const state, int is_compress,
144145
/* Get parameter bounds */
145146
if (is_compress) {
146147
bounds = ZSTD_cParam_getBounds(key_v);
147-
} else {
148+
}
149+
else {
148150
bounds = ZSTD_dParam_getBounds(key_v);
149151
}
150152
if (ZSTD_isError(bounds.error)) {
@@ -419,7 +421,8 @@ _zstd__get_param_bounds_impl(PyObject *module, int is_compress,
419421
set_zstd_error(mod_state, ERR_GET_C_BOUNDS, bound.error);
420422
return NULL;
421423
}
422-
} else {
424+
}
425+
else {
423426
bound = ZSTD_dParam_getBounds(parameter);
424427
if (ZSTD_isError(bound.error)) {
425428
_zstd_state* const mod_state = get_zstd_state(module);

Modules/_zstd/buffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ _OutputBuffer_InitWithSize(_BlocksOutputBuffer *buffer, ZSTD_outBuffer *ob,
4444
/* Get block size */
4545
if (0 <= max_length && max_length < init_size) {
4646
block_size = max_length;
47-
} else {
47+
}
48+
else {
4849
block_size = init_size;
4950
}
5051

Modules/_zstd/compressor.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ _PyZstd_set_c_parameters(ZstdCompressor *self, PyObject *level_or_options,
9494
if (key_v == ZSTD_c_compressionLevel) {
9595
/* Save for generating ZSTD_CDICT */
9696
self->compression_level = value_v;
97-
} else if (key_v == ZSTD_c_nbWorkers) {
97+
}
98+
else if (key_v == ZSTD_c_nbWorkers) {
9899
/* From zstd library doc:
99100
1. When nbWorkers >= 1, triggers asynchronous mode when
100101
used with ZSTD_compressStream2().
@@ -177,7 +178,8 @@ _get_CDict(ZstdDict *self, int compressionLevel)
177178
goto error;
178179
}
179180
Py_DECREF(capsule);
180-
} else {
181+
}
182+
else {
181183
/* ZSTD_CDict instance already exists */
182184
cdict = PyCapsule_GetPointer(capsule, NULL);
183185
}
@@ -206,7 +208,8 @@ _PyZstd_load_c_dict(ZstdCompressor *self, PyObject *dict) {
206208
ret = PyObject_IsInstance(dict, (PyObject*)mod_state->ZstdDict_type);
207209
if (ret < 0) {
208210
return -1;
209-
} else if (ret > 0) {
211+
}
212+
else if (ret > 0) {
210213
/* When compressing, use undigested dictionary by default. */
211214
zd = (ZstdDict*)dict;
212215
type = DICT_TYPE_UNDIGESTED;
@@ -220,7 +223,8 @@ _PyZstd_load_c_dict(ZstdCompressor *self, PyObject *dict) {
220223
(PyObject*)mod_state->ZstdDict_type);
221224
if (ret < 0) {
222225
return -1;
223-
} else if (ret > 0) {
226+
}
227+
else if (ret > 0) {
224228
/* type == -1 may indicate an error. */
225229
type = PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
226230
if (type == DICT_TYPE_DIGESTED ||
@@ -251,7 +255,8 @@ _PyZstd_load_c_dict(ZstdCompressor *self, PyObject *dict) {
251255
Py_BEGIN_CRITICAL_SECTION(self);
252256
zstd_ret = ZSTD_CCtx_refCDict(self->cctx, c_dict);
253257
Py_END_CRITICAL_SECTION();
254-
} else if (type == DICT_TYPE_UNDIGESTED) {
258+
}
259+
else if (type == DICT_TYPE_UNDIGESTED) {
255260
/* Load a dictionary.
256261
It doesn't override compression context's parameters. */
257262
Py_BEGIN_CRITICAL_SECTION2(self, zd);
@@ -260,15 +265,17 @@ _PyZstd_load_c_dict(ZstdCompressor *self, PyObject *dict) {
260265
PyBytes_AS_STRING(zd->dict_content),
261266
Py_SIZE(zd->dict_content));
262267
Py_END_CRITICAL_SECTION2();
263-
} else if (type == DICT_TYPE_PREFIX) {
268+
}
269+
else if (type == DICT_TYPE_PREFIX) {
264270
/* Load a prefix */
265271
Py_BEGIN_CRITICAL_SECTION2(self, zd);
266272
zstd_ret = ZSTD_CCtx_refPrefix(
267273
self->cctx,
268274
PyBytes_AS_STRING(zd->dict_content),
269275
Py_SIZE(zd->dict_content));
270276
Py_END_CRITICAL_SECTION2();
271-
} else {
277+
}
278+
else {
272279
/* Impossible code path */
273280
PyErr_SetString(PyExc_SystemError,
274281
"load_c_dict() impossible code path");
@@ -412,7 +419,8 @@ compress_impl(ZstdCompressor *self, Py_buffer *data,
412419
in.src = data->buf;
413420
in.size = data->len;
414421
in.pos = 0;
415-
} else {
422+
}
423+
else {
416424
in.src = &in;
417425
in.size = 0;
418426
in.pos = 0;
@@ -511,7 +519,8 @@ compress_mt_continue_impl(ZstdCompressor *self, Py_buffer *data)
511519
if (_OutputBuffer_Grow(&buffer, &out) < 0) {
512520
goto error;
513521
}
514-
} else if (in.pos == in.size) {
522+
}
523+
else if (in.pos == in.size) {
515524
/* Finished */
516525
assert(mt_continue_should_break(&in, &out));
517526
break;
@@ -569,13 +578,15 @@ _zstd_ZstdCompressor_compress_impl(ZstdCompressor *self, Py_buffer *data,
569578
/* Compress */
570579
if (self->use_multithread && mode == ZSTD_e_continue) {
571580
ret = compress_mt_continue_impl(self, data);
572-
} else {
581+
}
582+
else {
573583
ret = compress_impl(self, data, mode);
574584
}
575585

576586
if (ret) {
577587
self->last_mode = mode;
578-
} else {
588+
}
589+
else {
579590
self->last_mode = ZSTD_e_end;
580591

581592
/* Resetting cctx's session never fail */
@@ -621,7 +632,8 @@ _zstd_ZstdCompressor_flush_impl(ZstdCompressor *self, int mode)
621632

622633
if (ret) {
623634
self->last_mode = mode;
624-
} else {
635+
}
636+
else {
625637
self->last_mode = ZSTD_e_end;
626638

627639
/* Resetting cctx's session never fail */

Modules/_zstd/decompressor.c

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ _PyZstd_load_d_dict(ZstdDecompressor *self, PyObject *dict)
131131
ret = PyObject_IsInstance(dict, (PyObject*)mod_state->ZstdDict_type);
132132
if (ret < 0) {
133133
return -1;
134-
} else if (ret > 0) {
134+
}
135+
else if (ret > 0) {
135136
/* When decompressing, use digested dictionary by default. */
136137
zd = (ZstdDict*)dict;
137138
type = DICT_TYPE_DIGESTED;
@@ -145,7 +146,8 @@ _PyZstd_load_d_dict(ZstdDecompressor *self, PyObject *dict)
145146
(PyObject*)mod_state->ZstdDict_type);
146147
if (ret < 0) {
147148
return -1;
148-
} else if (ret > 0) {
149+
}
150+
else if (ret > 0) {
149151
/* type == -1 may indicate an error. */
150152
type = PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
151153
if (type == DICT_TYPE_DIGESTED ||
@@ -175,23 +177,26 @@ _PyZstd_load_d_dict(ZstdDecompressor *self, PyObject *dict)
175177
Py_BEGIN_CRITICAL_SECTION(self);
176178
zstd_ret = ZSTD_DCtx_refDDict(self->dctx, d_dict);
177179
Py_END_CRITICAL_SECTION();
178-
} else if (type == DICT_TYPE_UNDIGESTED) {
180+
}
181+
else if (type == DICT_TYPE_UNDIGESTED) {
179182
/* Load a dictionary */
180183
Py_BEGIN_CRITICAL_SECTION2(self, zd);
181184
zstd_ret = ZSTD_DCtx_loadDictionary(
182185
self->dctx,
183186
PyBytes_AS_STRING(zd->dict_content),
184187
Py_SIZE(zd->dict_content));
185188
Py_END_CRITICAL_SECTION2();
186-
} else if (type == DICT_TYPE_PREFIX) {
189+
}
190+
else if (type == DICT_TYPE_PREFIX) {
187191
/* Load a prefix */
188192
Py_BEGIN_CRITICAL_SECTION2(self, zd);
189193
zstd_ret = ZSTD_DCtx_refPrefix(
190194
self->dctx,
191195
PyBytes_AS_STRING(zd->dict_content),
192196
Py_SIZE(zd->dict_content));
193197
Py_END_CRITICAL_SECTION2();
194-
} else {
198+
}
199+
else {
195200
/* Impossible code path */
196201
PyErr_SetString(PyExc_SystemError,
197202
"load_d_dict() impossible code path");
@@ -296,7 +301,8 @@ decompress_impl(ZstdDecompressor *self, ZSTD_inBuffer *in,
296301
if (_OutputBuffer_InitWithSize(&buffer, &out, max_length, initial_size) < 0) {
297302
goto error;
298303
}
299-
} else {
304+
}
305+
else {
300306
if (_OutputBuffer_InitAndGrow(&buffer, &out, max_length) < 0) {
301307
goto error;
302308
}
@@ -325,7 +331,8 @@ decompress_impl(ZstdDecompressor *self, ZSTD_inBuffer *in,
325331
self->eof = 1;
326332
break;
327333
}
328-
} else if (type == TYPE_ENDLESS_DECOMPRESSOR) {
334+
}
335+
else if (type == TYPE_ENDLESS_DECOMPRESSOR) {
329336
/* decompress() function supports multiple frames */
330337
self->at_frame_edge = (zstd_ret == 0) ? 1 : 0;
331338

@@ -351,7 +358,8 @@ decompress_impl(ZstdDecompressor *self, ZSTD_inBuffer *in,
351358
}
352359
assert(out.pos == 0);
353360

354-
} else if (in->pos == in->size) {
361+
}
362+
else if (in->pos == in->size) {
355363
/* Finished */
356364
break;
357365
}
@@ -406,7 +414,8 @@ stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length
406414
assert(ret == NULL);
407415
goto success;
408416
}
409-
} else if (type == TYPE_ENDLESS_DECOMPRESSOR) {
417+
}
418+
else if (type == TYPE_ENDLESS_DECOMPRESSOR) {
410419
/* Fast path for the first frame */
411420
if (self->at_frame_edge && self->in_begin == self->in_end) {
412421
/* Read decompressed size */
@@ -435,7 +444,8 @@ stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length
435444
in.src = data->buf;
436445
in.size = data->len;
437446
in.pos = 0;
438-
} else if (data->len == 0) {
447+
}
448+
else if (data->len == 0) {
439449
/* Has unconsumed data, fast path for b'' */
440450
assert(self->in_begin < self->in_end);
441451

@@ -444,7 +454,8 @@ stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length
444454
in.src = self->input_buffer + self->in_begin;
445455
in.size = self->in_end - self->in_begin;
446456
in.pos = 0;
447-
} else {
457+
}
458+
else {
448459
/* Has unconsumed data */
449460
use_input_buffer = 1;
450461

@@ -485,7 +496,8 @@ stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length
485496
/* Set begin & end position */
486497
self->in_begin = 0;
487498
self->in_end = used_now;
488-
} else if (avail_now < (size_t) data->len) {
499+
}
500+
else if (avail_now < (size_t) data->len) {
489501
/* Move unconsumed data to the beginning.
490502
Overlap is possible, so use memmove(). */
491503
memmove(self->input_buffer,
@@ -520,13 +532,16 @@ stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length
520532
if (type == TYPE_DECOMPRESSOR) {
521533
if (Py_SIZE(ret) == max_length || self->eof) {
522534
self->needs_input = 0;
523-
} else {
535+
}
536+
else {
524537
self->needs_input = 1;
525538
}
526-
} else if (type == TYPE_ENDLESS_DECOMPRESSOR) {
539+
}
540+
else if (type == TYPE_ENDLESS_DECOMPRESSOR) {
527541
if (Py_SIZE(ret) == max_length && !self->at_frame_edge) {
528542
self->needs_input = 0;
529-
} else {
543+
}
544+
else {
530545
self->needs_input = 1;
531546
}
532547
}
@@ -536,7 +551,8 @@ stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length
536551
self->in_begin = 0;
537552
self->in_end = 0;
538553
}
539-
} else {
554+
}
555+
else {
540556
size_t data_size = in.size - in.pos;
541557

542558
self->needs_input = 0;
@@ -570,7 +586,8 @@ stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length
570586
memcpy(self->input_buffer, (char*)in.src + in.pos, data_size);
571587
self->in_begin = 0;
572588
self->in_end = data_size;
573-
} else {
589+
}
590+
else {
574591
/* Use input buffer */
575592
self->in_begin += in.pos;
576593
}
@@ -726,14 +743,16 @@ _zstd_ZstdDecompressor_unused_data_get_impl(ZstdDecompressor *self)
726743
}
727744
ret = mod_state->empty_bytes;
728745
Py_INCREF(ret);
729-
} else {
746+
}
747+
else {
730748
if (self->unused_data == NULL) {
731749
self->unused_data = PyBytes_FromStringAndSize(
732750
self->input_buffer + self->in_begin,
733751
self->in_end - self->in_begin);
734752
ret = self->unused_data;
735753
Py_XINCREF(ret);
736-
} else {
754+
}
755+
else {
737756
ret = self->unused_data;
738757
Py_INCREF(ret);
739758
}

0 commit comments

Comments
 (0)
0