From bf7c3aa69bca4c1a0f707e46851efc7e0ea9f8de Mon Sep 17 00:00:00 2001 From: someone Date: Mon, 9 May 2022 00:39:12 +0300 Subject: [PATCH] Use arg name from overriden JSONEncoder.encode method --- server/protocol/protocol.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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=(",", ":"))