You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, I am trying to set the alias of the Struct field, via typing.Annotated[], however, the following code fails.
from __future__ importannotationsimportmsgspecimporthikariimportjsonimporttypingastclassPayloadBase(msgspec.Struct):
@classmethoddef_from_payload(cls, payload: str) ->t.Self:
returnmsgspec.json.decode(payload, type=cls, strict=False, dec_hook=cls._decode_hook)
@propertydef_to_payload(self) ->str:
returnmsgspec.json.encode(self, enc_hook=self._encode_hook).decode()
@classmethoddef_decode_hook(cls, type: t.Type[t.Any], obj: t.Any) ->t.Any:
iftype==hikari.Snowflake:
returnhikari.Snowflake(int(obj))
raiseValueError("Sorry, but this value does not exist.")
@classmethoddef_encode_hook(cls, type: t.Type[hikari.Snowflake]) ->t.Any:
returnstr(type)
classReady(PayloadBase):
session_id: str=msgspec.field(name="sessionId")
resumed: bool=msgspec.field()
guild_id: t.Annotated[hikari.Snowflake, msgspec.field(name="guildId")]
bot=hikari.GatewayBot("...", banner=None, suppress_optimization_warning=True)
payload= {
"sessionId":"beanos",
"resumed":True,
"guildId":"1234567890"
}
ready=Ready._from_payload(json.dumps(payload))
print(ready.guild_id, type(ready.guild_id))
print(ready.session_id)
assertready.session_id=="beanos"assertready.resumedisTrueassertready.guild_id==hikari.Snowflake(1234567890)
It decodes the session properly, however, it does not decode the guild properly, and fails on it, because its using t.Annotated. Am I doing something wrong, or is this expected behavior?
The text was updated successfully, but these errors were encountered:
Question
Basically, I am trying to set the alias of the Struct field, via
typing.Annotated[]
, however, the following code fails.It decodes the session properly, however, it does not decode the guild properly, and fails on it, because its using
t.Annotated
. Am I doing something wrong, or is this expected behavior?The text was updated successfully, but these errors were encountered: