Repository: hikari-py/hikari
Pull request #1095 (2022-03-25 08:15:11)

Rename `nick` parameter to `nickname` on rest methods.
### Summary
<!-- Small summary of the merge request -->

### Checklist
<!-- Make sure to tick all the following boxes by putting an `x` in between (like this `[x]`) -->
- [ ] I have run `nox` and all the pipelines have passed.
- [ ] I have made unittests according to the code I have added/modified/deleted.

### Related issues
<!--
To mention an issue use `#issue-id` and to mention a merge request use `!merge-request-id`
To close/fix an issue use `Close #issue-id` or `Fix #issue-id` (depending on the merge request)
-->



Patch:
diff --git a/changes/1095.deprecation.md b/changes/1095.deprecation.md
new file mode 100644
index 00000000..628859f8
--- /dev/null
+++ b/changes/1095.deprecation.md
@@ -0,0 +1,1 @@
+Renamed `nick` argument to `nickname` for edit member and add user to guild REST methods.
diff --git a/hikari/api/rest.py b/hikari/api/rest.py
index 867a11e5..3502e1e8 100644
--- a/hikari/api/rest.py
+++ b/hikari/api/rest.py
@@ -3253,6 +3253,7 @@ async def add_user_to_guild(
         guild: snowflakes.SnowflakeishOr[guilds.PartialGuild],
         user: snowflakes.SnowflakeishOr[users.PartialUser],
         *,
+        nickname: undefined.UndefinedOr[str] = undefined.UNDEFINED,
         nick: undefined.UndefinedOr[str] = undefined.UNDEFINED,
         roles: undefined.UndefinedOr[snowflakes.SnowflakeishSequence[guilds.PartialRole]] = undefined.UNDEFINED,
         mute: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
@@ -3279,10 +3280,12 @@ async def add_user_to_guild(
 
         Other Parameters
         ----------------
-        nick : hikari.undefined.UndefinedOr[builtins.str]
+        nickname : hikari.undefined.UndefinedOr[builtins.str]
             If provided, the nick to add to the user when he joins the guild.
 
             Requires the `MANAGE_NICKNAMES` permission on the guild.
+        nick : hikari.undefined.UndefinedOr[builtins.str]
+            Deprecated alias for `nickname`.
         roles : hikari.undefined.UndefinedOr[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole]]
             If provided, the roles to add to the user when he joins the guild.
             This may be a collection objects or IDs of existing roles.
@@ -4972,6 +4975,7 @@ async def edit_member(
         guild: snowflakes.SnowflakeishOr[guilds.PartialGuild],
         user: snowflakes.SnowflakeishOr[users.PartialUser],
         *,
+        nickname: undefined.UndefinedNoneOr[str] = undefined.UNDEFINED,
         nick: undefined.UndefinedNoneOr[str] = undefined.UNDEFINED,
         roles: undefined.UndefinedOr[snowflakes.SnowflakeishSequence[guilds.PartialRole]] = undefined.UNDEFINED,
         mute: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
@@ -4995,11 +4999,13 @@ async def edit_member(
 
         Other Parameters
         ----------------
-        nick : hikari.undefined.UndefinedNoneOr[builtins.str]
+        nickname : hikari.undefined.UndefinedNoneOr[builtins.str]
             If provided, the new nick for the member. If `builtins.None`,
             will remove the members nick.
 
             Requires the `MANAGE_NICKNAMES` permission.
+        nick : hikari.undefined.UndefinedOr[builtins.str]
+            Deprecated alias for `nickname`.
         roles : hikari.undefined.UndefinedOr[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole]]
             If provided, the new roles for the member.
 
diff --git a/hikari/guilds.py b/hikari/guilds.py
index c1427102..f68fa3b8 100644
--- a/hikari/guilds.py
+++ b/hikari/guilds.py
@@ -66,6 +66,7 @@
 from hikari import urls
 from hikari import users
 from hikari.internal import attr_extensions
+from hikari.internal import deprecation
 from hikari.internal import enums
 from hikari.internal import routes
 from hikari.internal import time
@@ -921,6 +922,7 @@ async def remove_role(
     async def edit(
         self,
         *,
+        nickname: undefined.UndefinedNoneOr[str] = undefined.UNDEFINED,
         nick: undefined.UndefinedNoneOr[str] = undefined.UNDEFINED,
         roles: undefined.UndefinedOr[snowflakes.SnowflakeishSequence[PartialRole]] = undefined.UNDEFINED,
         mute: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
@@ -935,11 +937,13 @@ async def edit(
 
         Other Parameters
         ----------------
-        nick : hikari.undefined.UndefinedNoneOr[builtins.str]
+        nickname : hikari.undefined.UndefinedNoneOr[builtins.str]
             If provided, the new nick for the member. If `builtins.None`,
             will remove the members nick.
 
             Requires the `MANAGE_NICKNAMES` permission.
+        nick : hikari.undefined.UndefinedNoneOr[builtins.str]
+            Deprecated alias for `nickname`.
         roles : hikari.undefined.UndefinedOr[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole]]
             If provided, the new roles for the member.
 
@@ -1003,10 +1007,14 @@ async def edit(
         hikari.errors.InternalServerError
             If an internal error occurs on Discord while handling the request.
         """
+        if nick is not undefined.UNDEFINED:
+            deprecation.warn_deprecated("nick", alternative="nickname")
+            nickname = nick
+
         return await self.user.app.rest.edit_member(
             self.guild_id,
             self.user.id,
-            nick=nick,
+            nickname=nickname,
             roles=roles,
             mute=mute,
             deaf=deaf,
diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py
index 1054094b..b3421104 100644
--- a/hikari/impl/rest.py
+++ b/hikari/impl/rest.py
@@ -2053,15 +2053,20 @@ async def add_user_to_guild(
         guild: snowflakes.SnowflakeishOr[guilds.PartialGuild],
         user: snowflakes.SnowflakeishOr[users.PartialUser],
         *,
+        nickname: undefined.UndefinedOr[str] = undefined.UNDEFINED,
         nick: undefined.UndefinedOr[str] = undefined.UNDEFINED,
         roles: undefined.UndefinedOr[snowflakes.SnowflakeishSequence[guilds.PartialRole]] = undefined.UNDEFINED,
         mute: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
         deaf: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
     ) -> typing.Optional[guilds.Member]:
+        if nick is not undefined.UNDEFINED:
+            deprecation.warn_deprecated("nick", alternative="nickname")
+            nickname = nick
+
         route = routes.PUT_GUILD_MEMBER.compile(guild=guild, user=user)
         body = data_binding.JSONObjectBuilder()
         body.put("access_token", str(access_token))
-        body.put("nick", nick)
+        body.put("nick", nickname)
         body.put("mute", mute)
         body.put("deaf", deaf)
         body.put_snowflake_array("roles", roles)
@@ -2627,6 +2632,7 @@ async def edit_member(
         guild: snowflakes.SnowflakeishOr[guilds.PartialGuild],
         user: snowflakes.SnowflakeishOr[users.PartialUser],
         *,
+        nickname: undefined.UndefinedNoneOr[str] = undefined.UNDEFINED,
         nick: undefined.UndefinedNoneOr[str] = undefined.UNDEFINED,
         roles: undefined.UndefinedOr[snowflakes.SnowflakeishSequence[guilds.PartialRole]] = undefined.UNDEFINED,
         mute: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
@@ -2637,9 +2643,13 @@ async def edit_member(
         communication_disabled_until: undefined.UndefinedNoneOr[datetime.datetime] = undefined.UNDEFINED,
         reason: undefined.UndefinedOr[str] = undefined.UNDEFINED,
     ) -> guilds.Member:
+        if nick is not undefined.UNDEFINED:
+            deprecation.warn_deprecated("nick", alternative="nickname")
+            nickname = nick
+
         route = routes.PATCH_GUILD_MEMBER.compile(guild=guild, user=user)
         body = data_binding.JSONObjectBuilder()
-        body.put("nick", nick)
+        body.put("nick", nickname)
         body.put("mute", mute)
         body.put("deaf", deaf)
         body.put_snowflake_array("roles", roles)


Test patch:
diff --git a/tests/hikari/impl/test_rest.py b/tests/hikari/impl/test_rest.py
index 5b15e922..f6bf5f94 100644
--- a/tests/hikari/impl/test_rest.py
+++ b/tests/hikari/impl/test_rest.py
@@ -3361,7 +3361,7 @@ async def test_add_user_to_guild(self, rest_client):
             "token",
             StubModel(123),
             StubModel(456),
-            nick="cool nick",
+            nickname="cool nick",
             roles=[StubModel(234), StubModel(567)],
             mute=True,
             deaf=False,
@@ -3371,6 +3371,28 @@ async def test_add_user_to_guild(self, rest_client):
         rest_client._request.assert_awaited_once_with(expected_route, json=expected_json)
         rest_client._entity_factory.deserialize_member.assert_called_once_with({"id": "789"}, guild_id=123)
 
+    async def test_add_user_to_guild_with_deprecated_nick_field(self, rest_client):
+        member = StubModel(789)
+        expected_route = routes.PUT_GUILD_MEMBER.compile(guild=123, user=456)
+        expected_json = {"access_token": "token", "nick": "cool nick2"}
+        rest_client._request = mock.AsyncMock(return_value={"id": "789"})
+        rest_client._entity_factory.deserialize_member = mock.Mock(return_value=member)
+
+        with pytest.warns(
+            DeprecationWarning,
+            match="'nick' is deprecated and will be removed in a following version. You can use 'nickname' instead.",
+        ):
+            returned = await rest_client.add_user_to_guild(
+                "token",
+                StubModel(123),
+                StubModel(456),
+                nick="cool nick2",
+            )
+
+        assert returned is member
+        rest_client._request.assert_awaited_once_with(expected_route, json=expected_json)
+        rest_client._entity_factory.deserialize_member.assert_called_once_with({"id": "789"}, guild_id=123)
+
     async def test_add_user_to_guild_when_already_in_guild(self, rest_client):
         expected_route = routes.PUT_GUILD_MEMBER.compile(guild=123, user=456)
         expected_json = {"access_token": "token"}
@@ -4008,7 +4030,7 @@ async def test_edit_member(self, rest_client):
         result = await rest_client.edit_member(
             StubModel(123),
             StubModel(456),
-            nick="test",
+            nickname="test",
             roles=[StubModel(654), StubModel(321)],
             mute=True,
             deaf=False,
@@ -4023,6 +4045,24 @@ async def test_edit_member(self, rest_client):
         )
         rest_client._request.assert_awaited_once_with(expected_route, json=expected_json, reason="because i can")
 
+    async def test_edit_member_with_deprecated_nick_field(self, rest_client):
+        expected_route = routes.PATCH_GUILD_MEMBER.compile(guild=123, user=456)
+        expected_json = {"nick": "eeeeeestrogen"}
+        rest_client._request = mock.AsyncMock(return_value={"id": "789"})
+
+        with pytest.warns(
+            DeprecationWarning,
+            match="'nick' is deprecated and will be removed in a following version. You can use 'nickname' instead.",
+        ):
+            result = await rest_client.edit_member(StubModel(123), StubModel(456), nick="eeeeeestrogen")
+
+        assert result is rest_client._entity_factory.deserialize_member.return_value
+
+        rest_client._entity_factory.deserialize_member.assert_called_once_with(
+            rest_client._request.return_value, guild_id=123
+        )
+        rest_client._request.assert_awaited_once_with(expected_route, json=expected_json, reason=undefined.UNDEFINED)
+
     async def test_edit_member_when_voice_channel_is_None(self, rest_client):
         expected_route = routes.PATCH_GUILD_MEMBER.compile(guild=123, user=456)
         expected_json = {"nick": "test", "roles": ["654", "321"], "mute": True, "deaf": False, "channel_id": None}
@@ -4031,7 +4071,7 @@ async def test_edit_member_when_voice_channel_is_None(self, rest_client):
         result = await rest_client.edit_member(
             StubModel(123),
             StubModel(456),
-            nick="test",
+            nickname="test",
             roles=[StubModel(654), StubModel(321)],
             mute=True,
             deaf=False,
diff --git a/tests/hikari/test_guilds.py b/tests/hikari/test_guilds.py
index 3caf43cc..be274883 100644
--- a/tests/hikari/test_guilds.py
+++ b/tests/hikari/test_guilds.py
@@ -429,7 +429,7 @@ async def test_edit(self, model):
         model.app.rest.edit_member = mock.AsyncMock()
         disabled_until = datetime.datetime(2021, 11, 17)
         edit = await model.edit(
-            nick="Imposter",
+            nickname="Imposter",
             roles=[123, 432, 345],
             mute=False,
             deaf=True,
@@ -441,7 +441,7 @@ async def test_edit(self, model):
         model.app.rest.edit_member.assert_awaited_once_with(
             456,
             123,
-            nick="Imposter",
+            nickname="Imposter",
             roles=[123, 432, 345],
             mute=False,
             deaf=True,
@@ -452,6 +452,29 @@ async def test_edit(self, model):
 
         assert edit == model.app.rest.edit_member.return_value
 
+    @pytest.mark.asyncio()
+    async def test_edit_when_deprecated_nick_field(self, model):
+        model.app.rest.edit_member = mock.AsyncMock()
+
+        with pytest.warns(
+            DeprecationWarning,
+            match="'nick' is deprecated and will be removed in a following version. You can use 'nickname' instead.",
+        ):
+            edit = await model.edit(nick="meow")
+
+        model.app.rest.edit_member.assert_awaited_once_with(
+            456,
+            123,
+            nickname="meow",
+            roles=undefined.UNDEFINED,
+            mute=undefined.UNDEFINED,
+            deaf=undefined.UNDEFINED,
+            voice_channel=undefined.UNDEFINED,
+            communication_disabled_until=undefined.UNDEFINED,
+            reason=undefined.UNDEFINED,
+        )
+        assert edit == model.app.rest.edit_member.return_value
+
     def test_default_avatar_url_property(self, model, mock_user):
         assert model.default_avatar_url is mock_user.default_avatar_url