From 452574ff20cd1588d975f04a5af9ee41fdc76953 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 13 Aug 2017 16:06:25 -0700 Subject: [PATCH] [types] rename Model.update to Model.inplace_update We want to use update elsewhere, so lets make this method more explicit --- disco/state.py | 12 ++++++------ disco/types/base.py | 6 ++++-- tests/types/base.py | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/disco/state.py b/disco/state.py index 94888e9..26c9eba 100644 --- a/disco/state.py +++ b/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 diff --git a/disco/types/base.py b/disco/types/base.py index fb15cff..111b8a9 100644 --- a/disco/types/base.py +++ b/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 diff --git a/tests/types/base.py b/tests/types/base.py index 5da7ea1..4273049 100644 --- a/tests/types/base.py +++ b/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