Repository: hikari-py/hikari
Pull request #1527 (2023-03-01 15:52:21)

Default token_type to "Bot" when initialising RESTBot with str token
### 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/1527.feature.md b/changes/1527.feature.md
new file mode 100644
index 00000000..9bf02ed7
--- /dev/null
+++ b/changes/1527.feature.md
@@ -0,0 +1,1 @@
+`token_type` now defaults to `"Bot"` when initialising `RESTBot` with a string token.
diff --git a/hikari/impl/rest_bot.py b/hikari/impl/rest_bot.py
index 8a56ed90..39991954 100644
--- a/hikari/impl/rest_bot.py
+++ b/hikari/impl/rest_bot.py
@@ -30,6 +30,7 @@
 import sys
 import typing
 
+from hikari import applications
 from hikari import errors
 from hikari import traits
 from hikari.api import interaction_server as interaction_server_
@@ -47,7 +48,6 @@
     import socket as socket_
     import ssl
 
-    from hikari import applications
     from hikari.api import entity_factory as entity_factory_api
     from hikari.api import rest as rest_api
     from hikari.api import special_endpoints
@@ -78,7 +78,8 @@ class RESTBot(traits.RESTBotAware, interaction_server_.InteractionServer):
         The bot or bearer token.
     token_type : typing.Union[str, hikari.applications.TokenType, None]
         The type of token in use. This should only be passed when `str`
-        is passed for `token`, can be `"Bot"` or `"Bearer"`.
+        is passed for `token`, can be `"Bot"` or `"Bearer"` and defaults
+        to `"Bot".
 
         This should be left as `None` when `hikari.api.rest.TokenStrategy`
         is passed for `token`.
@@ -259,7 +260,7 @@ def __init__(
     def __init__(
         self,
         token: str,
-        token_type: typing.Union[str, applications.TokenType],
+        token_type: typing.Union[str, applications.TokenType] = applications.TokenType.BOT,
         public_key: typing.Union[bytes, str, None] = None,
         *,
         allow_color: bool = True,
@@ -300,6 +301,9 @@ def __init__(
         if isinstance(token, str):
             token = token.strip()
 
+            if token_type is None:
+                token_type = applications.TokenType.BOT
+
         # Beautification and logging
         ux.init_logging(logs, allow_color, force_color)
         self.print_banner(banner, allow_color, force_color)


Test patch:
diff --git a/tests/hikari/impl/test_rest_bot.py b/tests/hikari/impl/test_rest_bot.py
index 2d846aaf..79d10e99 100644
--- a/tests/hikari/impl/test_rest_bot.py
+++ b/tests/hikari/impl/test_rest_bot.py
@@ -213,7 +213,7 @@ def test___init___generates_default_settings(self):
         stack.enter_context(mock.patch.object(interaction_server_impl, "InteractionServer"))
 
         with stack:
-            result = cls("token", "token_type")
+            result = cls("token")
 
             rest_impl.RESTClientImpl.assert_called_once_with(
                 cache=None,
@@ -225,7 +225,7 @@ def test___init___generates_default_settings(self):
                 proxy_settings=config.ProxySettings.return_value,
                 rest_url=None,
                 token="token",
-                token_type="token_type",
+                token_type="Bot",
             )
 
             config.HTTPSettings.assert_called_once()