Skip to content

Commit

Permalink
Use arg name from overriden JSONEncoder.encode method
Browse files Browse the repository at this point in the history
  • Loading branch information
someone authored and Gatsik committed May 8, 2022
1 parent 97eabaf commit bf7c3aa
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions server/protocol/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(",", ":"))
Expand Down

0 comments on commit bf7c3aa

Please sign in to comment.