diff --git a/server/protocol/protocol.py b/server/protocol/protocol.py index d996b1455..e0f73d963 100644 --- a/server/protocol/protocol.py +++ b/server/protocol/protocol.py @@ -12,19 +12,19 @@ class CustomJSONEncoder(json.JSONEncoder): # taken from https://stackoverflow.com/a/60243503 - def encode(self, obj): - if isinstance(obj, Mapping): + def encode(self, o): + if isinstance(o, Mapping): dict_content = ", ".join( f"{self.encode(key)}: {self.encode(value)}" - for (key, value) in obj.items() + for (key, value) in o.items() ) return '{' + dict_content + '}' - elif isinstance(obj, Iterable) and not isinstance(obj, str): - return "[" + ", ".join(map(self.encode, obj)) + "]" - elif isinstance(obj, float): - return f"{obj:.{config.JSON_FLOAT_DIGITS_PRECISION}f}" + elif isinstance(o, Iterable) and not isinstance(o, str): + return "[" + ", ".join(map(self.encode, o)) + "]" + elif isinstance(o, float): + return f"{o:.{config.JSON_FLOAT_DIGITS_PRECISION}f}" else: - return super().encode(obj) + return super().encode(o) json_encoder = CustomJSONEncoder(separators=(",", ":"))