Browse Source

bugfix - fields without a default but set to None would become UNSET

etc stuff as well
pull/11/head
Andrei 8 years ago
parent
commit
fca1599579
  1. 4
      disco/gateway/events.py
  2. 17
      disco/types/base.py
  3. 3
      disco/types/guild.py

4
disco/gateway/events.py

@ -7,7 +7,7 @@ from disco.types.user import User, Presence
from disco.types.channel import Channel from disco.types.channel import Channel
from disco.types.message import Message, MessageReactionEmoji from disco.types.message import Message, MessageReactionEmoji
from disco.types.voice import VoiceState from disco.types.voice import VoiceState
from disco.types.guild import Guild, GuildMember, Role, Emoji from disco.types.guild import Guild, GuildMember, Role, GuildEmoji
from disco.types.base import Model, ModelMeta, Field, ListField, snowflake, lazy_datetime from disco.types.base import Model, ModelMeta, Field, ListField, snowflake, lazy_datetime
@ -295,7 +295,7 @@ class GuildEmojisUpdate(GatewayEvent):
The new set of emojis for the guild The new set of emojis for the guild
""" """
guild_id = Field(snowflake) guild_id = Field(snowflake)
emojis = ListField(Emoji) emojis = ListField(GuildEmoji)
class GuildIntegrationsUpdate(GatewayEvent): class GuildIntegrationsUpdate(GatewayEvent):

17
disco/types/base.py

@ -290,18 +290,21 @@ class Model(six.with_metaclass(ModelMeta, AsyncChainable)):
should_skip = skip and name in skip should_skip = skip and name in skip
if consume and not should_skip: if consume and not should_skip:
raw = obj.pop(field.src_name, None) raw = obj.pop(field.src_name, UNSET)
else: else:
raw = obj.get(field.src_name, None) raw = obj.get(field.src_name, UNSET)
if raw is None or should_skip: # If the field is unset/none, and we have a default we need to set it
if field.has_default(): if (raw in (None, UNSET) or should_skip) and field.has_default():
default = field.default() if callable(field.default) else field.default default = field.default() if callable(field.default) else field.default
else:
default = UNSET
setattr(self, field.dst_name, default) setattr(self, field.dst_name, default)
continue continue
# Otherwise if the field is UNSET and has no default, skip conversion
if raw is UNSET or should_skip:
setattr(self, field.dst_name, raw)
continue
value = field.try_convert(raw, self.client) value = field.try_convert(raw, self.client)
setattr(self, field.dst_name, value) setattr(self, field.dst_name, value)

3
disco/types/guild.py

@ -49,6 +49,9 @@ class GuildEmoji(Emoji):
managed = Field(bool) managed = Field(bool)
roles = ListField(snowflake) roles = ListField(snowflake)
def __str__(self):
return u'<:{}:{}>'.format(self.name, self.id)
@property @property
def url(self): def url(self):
return 'https://discordapp.com/api/emojis/{}.png'.format(self.id) return 'https://discordapp.com/api/emojis/{}.png'.format(self.id)

Loading…
Cancel
Save