Browse Source

[types] rename Model.update to Model.inplace_update

We want to use update elsewhere, so lets make this method more explicit
pull/54/head
Andrei 8 years ago
parent
commit
452574ff20
  1. 12
      disco/state.py
  2. 6
      disco/types/base.py
  3. 2
      tests/types/base.py

12
disco/state.py

@ -198,7 +198,7 @@ class State(object):
event.guild.sync()
def on_guild_update(self, event):
self.guilds[event.guild.id].update(event.guild, ignored=[
self.guilds[event.guild.id].inplace_update(event.guild, ignored=[
'channels',
'members',
'voice_states',
@ -220,7 +220,7 @@ class State(object):
def on_channel_update(self, event):
if event.channel.id in self.channels:
self.channels[event.channel.id].update(event.channel)
self.channels[event.channel.id].inplace_update(event.channel)
if event.overwrites is not UNSET:
self.channels[event.channel.id].overwrites = event.overwrites
@ -237,7 +237,7 @@ class State(object):
if event.state.session_id in self.voice_states:
# Moving channels
if event.state.channel_id:
self.voice_states[event.state.session_id].update(event.state)
self.voice_states[event.state.session_id].inplace_update(event.state)
# Disconnection
else:
if event.state.guild_id in self.guilds:
@ -268,7 +268,7 @@ class State(object):
if event.member.id not in self.guilds[event.member.guild_id].members:
return
self.guilds[event.member.guild_id].members[event.member.id].update(event.member)
self.guilds[event.member.guild_id].members[event.member.id].inplace_update(event.member)
def on_guild_member_remove(self, event):
if event.guild_id not in self.guilds:
@ -303,7 +303,7 @@ class State(object):
if event.guild_id not in self.guilds:
return
self.guilds[event.guild_id].roles[event.role.id].update(event.role)
self.guilds[event.guild_id].roles[event.role.id].inplace_update(event.role)
def on_guild_role_delete(self, event):
if event.guild_id not in self.guilds:
@ -331,7 +331,7 @@ class State(object):
# if we have the user tracked locally, we can just use the presence
# update to update both their presence and the cached user object.
if user.id in self.users:
self.users[user.id].update(user)
self.users[user.id].inplace_update(user)
else:
# Otherwise this user does not exist in our local cache, so we can
# use this opportunity to add them. They will quickly fall out of

6
disco/types/base.py

@ -76,7 +76,9 @@ class Field(object):
if isinstance(self.deserializer, Field) and self.default is None:
self.default = self.deserializer.default
elif inspect.isclass(self.deserializer) and issubclass(self.deserializer, Model) and self.default is None and create:
elif (inspect.isclass(self.deserializer) and
issubclass(self.deserializer, Model) and
self.default is None and create):
self.default = self.deserializer
@property
@ -356,7 +358,7 @@ class Model(six.with_metaclass(ModelMeta, Chainable)):
value = field.try_convert(raw, inst.client, consume=consume)
setattr(inst, field.dst_name, value)
def update(self, other, ignored=None):
def inplace_update(self, other, ignored=None):
for name in six.iterkeys(self._fields):
if ignored and name in ignored:
continue

2
tests/types/base.py

@ -27,5 +27,5 @@ def test_cached_property(model):
def test_cached_property_clear_on_update(model):
inst = model(a=1, b=3)
assert inst.value == 4
inst.update(model(a=2, b=3))
inst.inplace_update(model(a=2, b=3))
assert inst.value == 5

Loading…
Cancel
Save