Skip to content

Commit eb7cc98

Browse files
committed
Lint hazelcast/serialization
Linted the files at the `hazelcast/serialization` folder and removed its exclusion from `pyproject.toml`.
1 parent f14b477 commit eb7cc98

File tree

15 files changed

+282
-138
lines changed

15 files changed

+282
-138
lines changed

hazelcast/serialization/api.py

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def skip_bytes(self, count):
236236

237237
def read_boolean(self):
238238
"""Reads 1 byte from input stream and convert it to a bool value.
239-
239+
240240
Returns:
241241
bool: The bool value read.
242242
"""
@@ -252,23 +252,23 @@ def read_byte(self):
252252

253253
def read_unsigned_byte(self):
254254
"""Reads 1 byte from input stream, zero-extends it and returns.
255-
255+
256256
Returns:
257257
int: The unsigned byte value read.
258258
"""
259259
raise NotImplementedError()
260260

261261
def read_short(self):
262262
"""Reads 2 bytes from input stream and returns a short value.
263-
263+
264264
Returns:
265265
int: The short value read.
266266
"""
267267
raise NotImplementedError()
268268

269269
def read_unsigned_short(self):
270270
"""Reads 2 bytes from input stream and returns an int value.
271-
271+
272272
Returns:
273273
int: The unsigned short value read.
274274
"""
@@ -284,119 +284,119 @@ def read_char(self):
284284

285285
def read_int(self):
286286
"""Reads 4 bytes from input stream and returns an int value.
287-
287+
288288
Returns:
289289
int: The int value read.
290290
"""
291291
raise NotImplementedError()
292292

293293
def read_long(self):
294294
"""Reads 8 bytes from input stream and returns a long value.
295-
295+
296296
Returns:
297297
int: The int value read.
298298
"""
299299
raise NotImplementedError()
300300

301301
def read_float(self):
302302
"""Reads 4 bytes from input stream and returns a float value.
303-
303+
304304
Returns:
305305
float: The float value read.
306306
"""
307307
raise NotImplementedError()
308308

309309
def read_double(self):
310310
"""Reads 8 bytes from input stream and returns a double value.
311-
311+
312312
Returns:
313313
float: The double value read.
314314
"""
315315
raise NotImplementedError()
316316

317317
def read_utf(self):
318318
"""Reads a UTF-8 string from input stream and returns it.
319-
319+
320320
Returns:
321321
str: The UTF-8 string read.
322322
"""
323323
raise NotImplementedError()
324324

325325
def read_byte_array(self):
326326
"""Reads a byte array from input stream and returns it.
327-
327+
328328
Returns:
329329
bytearray: The byte array read.
330330
"""
331331
raise NotImplementedError()
332332

333333
def read_boolean_array(self):
334334
"""Reads a bool array from input stream and returns it.
335-
335+
336336
Returns:
337337
list[bool]: The bool array read.
338338
"""
339339
raise NotImplementedError()
340340

341341
def read_char_array(self):
342342
"""Reads a char array from input stream and returns it.
343-
343+
344344
Returns:
345345
list[str]: The char array read.
346346
"""
347347
raise NotImplementedError()
348348

349349
def read_int_array(self):
350350
"""Reads a int array from input stream and returns it.
351-
351+
352352
Returns:
353353
list[int]: The int array read.
354354
"""
355355
raise NotImplementedError()
356356

357357
def read_long_array(self):
358358
"""Reads a long array from input stream and returns it.
359-
359+
360360
Returns:
361361
list[int]: The long array read.
362362
"""
363363
raise NotImplementedError()
364364

365365
def read_double_array(self):
366366
"""Reads a double array from input stream and returns it.
367-
367+
368368
Returns:
369369
list[float]: The double array read.
370370
"""
371371
raise NotImplementedError()
372372

373373
def read_float_array(self):
374374
"""Reads a float array from input stream and returns it.
375-
375+
376376
Returns:
377377
list[float]: The float array read.
378378
"""
379379
raise NotImplementedError()
380380

381381
def read_short_array(self):
382382
"""Reads a short array from input stream and returns it.
383-
383+
384384
Returns:
385385
list[int]: The short array read.
386386
"""
387387
raise NotImplementedError()
388388

389389
def read_utf_array(self):
390390
"""Reads a UTF-8 string array from input stream and returns it.
391-
391+
392392
Returns:
393393
list[str]: The UTF-8 string array read.
394394
"""
395395
raise NotImplementedError()
396396

397397
def read_object(self):
398398
"""Reads a object from input stream and returns it.
399-
399+
400400
Returns:
401401
The object read.
402402
"""
@@ -412,15 +412,15 @@ def get_byte_order(self):
412412

413413
def position(self):
414414
"""Returns current position in buffer.
415-
415+
416416
Returns:
417417
int: Current position in buffer.
418418
"""
419419
raise NotImplementedError()
420420

421421
def size(self):
422422
"""Returns size of buffer.
423-
423+
424424
Returns:
425425
int: size of buffer.
426426
"""
@@ -440,31 +440,39 @@ def write_data(self, object_data_output):
440440
Args:
441441
object_data_output (hazelcast.serialization.api.ObjectDataOutput): The output.
442442
"""
443-
raise NotImplementedError("read_data must be implemented to serialize this IdentifiedDataSerializable")
443+
raise NotImplementedError(
444+
"read_data must be implemented to serialize this IdentifiedDataSerializable"
445+
)
444446

445447
def read_data(self, object_data_input):
446448
"""Reads fields from the input stream.
447449
448450
Args:
449451
object_data_input (hazelcast.serialization.api.ObjectDataInput): The input.
450452
"""
451-
raise NotImplementedError("read_data must be implemented to deserialize this IdentifiedDataSerializable")
453+
raise NotImplementedError(
454+
"read_data must be implemented to deserialize this IdentifiedDataSerializable"
455+
)
452456

453457
def get_factory_id(self):
454458
"""Returns DataSerializableFactory factory id for this class.
455-
459+
456460
Returns:
457461
int: The factory id.
458462
"""
459-
raise NotImplementedError("This method must return the factory ID for this IdentifiedDataSerializable")
463+
raise NotImplementedError(
464+
"This method must return the factory ID for this IdentifiedDataSerializable"
465+
)
460466

461467
def get_class_id(self):
462468
"""Returns type identifier for this class. Id should be unique per DataSerializableFactory.
463-
469+
464470
Returns:
465471
int: The type id.
466472
"""
467-
raise NotImplementedError("This method must return the class ID for this IdentifiedDataSerializable")
473+
raise NotImplementedError(
474+
"This method must return the class ID for this IdentifiedDataSerializable"
475+
)
468476

469477

470478
class Portable(object):
@@ -496,15 +504,15 @@ def read_portable(self, reader):
496504

497505
def get_factory_id(self):
498506
"""Returns PortableFactory id for this portable class
499-
507+
500508
Returns:
501509
int: The factory id.
502510
"""
503511
raise NotImplementedError()
504512

505513
def get_class_id(self):
506514
"""Returns class identifier for this portable class. Class id should be unique per PortableFactory.
507-
515+
508516
Returns:
509517
int: The class id.
510518
"""
@@ -557,7 +565,7 @@ class PortableReader(object):
557565

558566
def get_version(self):
559567
"""Returns the global version of portable classes.
560-
568+
561569
Returns:
562570
int: Global version of portable classes.
563571
"""
@@ -576,7 +584,7 @@ def has_field(self, field_name):
576584

577585
def get_field_names(self):
578586
"""Returns the set of field names on this portable class.
579-
587+
580588
Returns:
581589
set: Set of field names on this portable class.
582590
"""
@@ -827,7 +835,7 @@ def read_portable_array(self, field_name):
827835
def get_raw_data_input(self):
828836
"""After reading portable fields, one can read remaining fields in old fashioned way
829837
consecutively from the end of stream. After get_raw_data_input() called, no data can be read.
830-
838+
831839
Returns:
832840
hazelcast.serialization.api.ObjectDataInput: The input.
833841
"""
@@ -1032,9 +1040,8 @@ def write_portable_array(self, field_name, values):
10321040
def get_raw_data_output(self):
10331041
"""After writing portable fields, one can write remaining fields in old fashioned way
10341042
consecutively at the end of stream. After get_raw_data_output() called, no data can be written.
1035-
1043+
10361044
Returns:
10371045
hazelcast.serialization.api.ObjectDataOutput: The output.
10381046
"""
10391047
raise NotImplementedError()
1040-

hazelcast/serialization/base.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def index_for_default_type(type_id):
4444

4545

4646
class BaseSerializationService(object):
47-
def __init__(self, version, global_partition_strategy, output_buffer_size, is_big_endian, int_type):
47+
def __init__(
48+
self, version, global_partition_strategy, output_buffer_size, is_big_endian, int_type
49+
):
4850
self._registry = SerializerRegistry(int_type)
4951
self._version = version
5052
self._global_partition_strategy = global_partition_strategy
@@ -116,7 +118,9 @@ def to_object(self, data):
116118

117119
def write_object(self, out, obj):
118120
if isinstance(obj, Data):
119-
raise HazelcastSerializationError("Cannot write a Data instance! Use write_data(out, data) instead.")
121+
raise HazelcastSerializationError(
122+
"Cannot write a Data instance! Use write_data(out, data) instead."
123+
)
120124
try:
121125
serializer = self._registry.serializer_for(obj)
122126
out.write_int(serializer.get_type_id())
@@ -130,7 +134,9 @@ def read_object(self, inp):
130134
serializer = self._registry.serializer_by_type_id(type_id)
131135
if serializer is None:
132136
if self._active:
133-
raise HazelcastSerializationError("Missing Serializer for type-id: %s" % type_id)
137+
raise HazelcastSerializationError(
138+
"Missing Serializer for type-id: %s" % type_id
139+
)
134140
else:
135141
raise HazelcastInstanceNotActiveError()
136142
return serializer.read(inp)
@@ -139,11 +145,17 @@ def read_object(self, inp):
139145

140146
def _calculate_partitioning_hash(self, obj, partitioning_strategy):
141147
partitioning_hash = 0
142-
_ps = partitioning_strategy if partitioning_strategy is not None else self._global_partition_strategy
148+
_ps = (
149+
partitioning_strategy
150+
if partitioning_strategy is not None
151+
else self._global_partition_strategy
152+
)
143153
pk = _ps(obj)
144154
if pk is not None and pk is not obj:
145155
partitioning_key = self.to_data(pk, empty_partitioning_strategy)
146-
partitioning_hash = 0 if partitioning_key is None else partitioning_key.get_partition_hash()
156+
partitioning_hash = (
157+
0 if partitioning_key is None else partitioning_key.get_partition_hash()
158+
)
147159
return partitioning_hash
148160

149161
def _create_data_output(self):
@@ -231,7 +243,9 @@ def serializer_for(self, obj):
231243
serializer = self.lookup_python_serializer(obj_type)
232244

233245
if serializer is None:
234-
raise HazelcastSerializationError("There is no suitable serializer for:" + str(obj_type))
246+
raise HazelcastSerializationError(
247+
"There is no suitable serializer for:" + str(obj_type)
248+
)
235249
return serializer
236250

237251
def lookup_default_serializer(self, obj_type, obj):
@@ -286,7 +300,9 @@ def lookup_global_serializer(self, obj_type):
286300

287301
def register_constant_serializer(self, serializer, object_type=None):
288302
stream_serializer = serializer
289-
self._constant_type_ids[index_for_default_type(stream_serializer.get_type_id())] = stream_serializer
303+
self._constant_type_ids[
304+
index_for_default_type(stream_serializer.get_type_id())
305+
] = stream_serializer
290306
if object_type is not None:
291307
self._constant_type_dict[object_type] = stream_serializer
292308

@@ -297,15 +313,19 @@ def safe_register_serializer(self, stream_serializer, obj_type=None):
297313
raise ValueError("[%s] serializer cannot be overridden!" % obj_type)
298314
current = self._type_dict.get(obj_type, None)
299315
if current is not None and current.__class__ != stream_serializer.__class__:
300-
raise ValueError("Serializer[%s] has been already registered for type: %s"
301-
% (current.__class__, obj_type))
316+
raise ValueError(
317+
"Serializer[%s] has been already registered for type: %s"
318+
% (current.__class__, obj_type)
319+
)
302320
else:
303321
self._type_dict[obj_type] = stream_serializer
304322
serializer_type_id = stream_serializer.get_type_id()
305323
current = self._id_dic.get(serializer_type_id, None)
306324
if current is not None and current.__class__ != stream_serializer.__class__:
307-
raise ValueError("Serializer[%s] has been already registered for type-id: %s"
308-
% (current.__class__, serializer_type_id))
325+
raise ValueError(
326+
"Serializer[%s] has been already registered for type-id: %s"
327+
% (current.__class__, serializer_type_id)
328+
)
309329
else:
310330
self._id_dic[serializer_type_id] = stream_serializer
311331
return current is None

0 commit comments

Comments
 (0)