misc(aurora): change the JSONEncoder subclass to use match/case instead of if statements

This commit is contained in:
Seaswimmer 2024-06-04 14:20:01 -04:00
parent 21fa3d9eb0
commit 8ac735dafe
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -1,5 +1,6 @@
import json
from datetime import datetime, timedelta
from typing import Any
from redbot.core.bot import Red
@ -7,15 +8,17 @@ from ..models.base import AuroraBaseModel
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime):
def default(self, o) -> Any:
match o:
case datetime():
return int(o.timestamp())
if isinstance(o, timedelta):
case timedelta():
return str(o)
if isinstance(o, AuroraBaseModel):
case AuroraBaseModel():
return o.dump()
if isinstance(o, Red):
case Red():
return None
case _:
return super().default(o)