Skip to content

Commit

Permalink
Fix player deserialize broken by zealous mypy compliance.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsTheFae committed Jan 31, 2024
1 parent 06f7b72 commit 7a129ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions musicbot/constructs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def default(self, o: "Serializable") -> Any:
def deserialize(cls, data: Dict[str, Any]) -> Any:
if all(x in data for x in Serializable.CLASS_SIGNATURE):
# log.debug("Deserialization requested for %s", data)
factory = type(pydoc.locate(data["__module__"] + "." + data["__class__"]))
factory = pydoc.locate(data["__module__"] + "." + data["__class__"])
# log.debug("Found object %s", factory)
if factory and issubclass(factory, Serializable):
if factory and issubclass(factory, Serializable): # type: ignore[arg-type]
# log.debug("Deserializing %s object", factory)
return factory._deserialize(
data["data"], **cls._get_vars(factory._deserialize)
return factory._deserialize( # type: ignore[attr-defined]
data["data"], **cls._get_vars(factory._deserialize) # type: ignore[attr-defined]
)

return data
Expand Down
4 changes: 4 additions & 0 deletions musicbot/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ def from_json(
obj = json.loads(raw_json, object_hook=Serializer.deserialize)
if isinstance(obj, MusicPlayer):
return obj
log.error(
"Deserialize returned a non-MusicPlayer: %s",
type(obj),
)
return None
except json.JSONDecodeError:
log.exception("Failed to deserialize player")
Expand Down

0 comments on commit 7a129ca

Please sign in to comment.