From bfb50b2bafeb148f400310badc764c8aae092938 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Sun, 7 Jan 2024 21:24:51 -0500 Subject: [PATCH] Using asdict instead of __dict__ --- pubnix.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pubnix.py b/pubnix.py index 10e3528..b70fab5 100644 --- a/pubnix.py +++ b/pubnix.py @@ -13,7 +13,7 @@ both server and client run on the same machine. """ from contextlib import contextmanager -from dataclasses import dataclass +from dataclasses import dataclass, asdict from pathlib import Path from threading import Thread from typing import Union @@ -235,12 +235,12 @@ def login(connection): # Messages ## -class MessageEncoder(json.JSONEncoder): +class DataclassEncoder(json.JSONEncoder): def default(self, o): - return o.__dict__ + return asdict(o) def send_message(connection, message): - contents = json.dumps(message, cls=MessageEncoder).encode() + contents = json.dumps(message, cls=DataclassEncoder).encode() connection.sendall(contents) def receive_message(connection, cls=None):