Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit 80516e9

Browse files
committed
fixed style issues
1 parent 6998a10 commit 80516e9

File tree

9 files changed

+37
-42
lines changed

9 files changed

+37
-42
lines changed

discord_ui/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from typing import Coroutine, Dict, List, Tuple, Union
2424
try:
2525
from typing import Literal
26-
except:
26+
except ImportError:
2727
from typing_extensions import Literal
2828

2929
logging = setup_logger(__name__)
@@ -289,7 +289,7 @@ async def sync_commands(self, delete_unused=None):
289289
Raises
290290
------
291291
:raises: :class:`InvalidArgument` : A slash command has an invalid guild_id
292-
:raises: :class:`InvalidArgument` : A slash command has an invalid id specified in the guild_permissions
292+
:raises: :class:`InvalidArgument` : A slash command has an invalid id specified in the guild_permissions
293293
294294
"""
295295
delete_unused = delete_unused or self.delete_unused
@@ -740,7 +740,7 @@ async def nuke_commands(self):
740740
logging.info("nuked all commands")
741741

742742

743-
def add_command(self, name, callback=None, description=MISSING, options=[], guild_ids=MISSING, default_permission=True, guild_permissions=MISSING, api=False) -> Union[None, Coroutine]:
743+
def add_command(self, name, callback=None, description=MISSING, options=MISSING, guild_ids=MISSING, default_permission=True, guild_permissions=MISSING, api=False) -> Union[None, Coroutine]:
744744
"""
745745
Adds a new slashcommand
746746
@@ -776,7 +776,7 @@ def add_command(self, name, callback=None, description=MISSING, options=[], guil
776776
if self.ready is False:
777777
raise Exception("Slashcommands are not ready yet")
778778
return self.create_command(command)
779-
def command(self, name=MISSING, description=MISSING, options=[], guild_ids=MISSING, default_permission=True, guild_permissions=MISSING):
779+
def command(self, name=MISSING, description=MISSING, options=MISSING, guild_ids=MISSING, default_permission=True, guild_permissions=MISSING):
780780
"""
781781
A decorator for a slash command
782782

discord_ui/cogs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
import asyncio
1111
import datetime
12-
import inspect
13-
from typing import Optional, Union
12+
from typing import Optional
1413
try:
1514
from typing import Literal
16-
except:
15+
except ImportError:
1716
from typing_extensions import Literal
1817

1918
class WrongListener(errors.CheckFailure):

discord_ui/component_list.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from discord.ext.commands.cooldowns import C
2-
from .receive import Interaction
3-
from .components import Button, Component
4-
from .cogs import ListeningComponent
5-
from .tools import MISSING
1+
# from .receive import Interaction
2+
# from .components import Button, Component
3+
# from .cogs import ListeningComponent
4+
# from .tools import MISSING
65

7-
from typing import List
8-
from inspect import getmembers
6+
# from typing import List
7+
# from inspect import getmembers
98

109
# .send(..., component_list=ComponentList(client))
1110

1211

13-
class _ListeningComp():
14-
pass
12+
# class _ListeningComp():
13+
# pass
1514

1615
# class ListeningButton(ListeningComponent, Button):
1716
# def __init__(self, callback, custom_id, label="\u200b", color="blurple", emoji=MISSING, new_line=False, disabled=False) -> None:

discord_ui/receive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from typing import List, Union, Dict
1414
try:
1515
from typing import Literal
16-
except:
16+
except ImportError:
1717
from typing_extensions import Literal
1818

1919
logging = setup_logger("discord-ui")
@@ -104,7 +104,7 @@ async def respond(self, content=MISSING, *, tts=False, embed=MISSING, embeds=MIS
104104
----------
105105
content: :class:`str`, optional
106106
The raw message content
107-
tts: :class:`bool`
107+
tts: :class:`bool`
108108
Whether the message should be send with text-to-speech
109109
embed: :class:`discord.Embed`
110110
Embed rich content
@@ -466,7 +466,7 @@ async def disable_action_row(self, row, disable = True):
466466
Raises
467467
------
468468
:raises: :class:`discord_ui.errors.OutOfValidRange` : The specified range was out of the possible range of the component rows
469-
:raises: :class:`discord_ui.errors.OutOfValidRange` : The specified row was out of the possible range of the component rows
469+
:raises: :class:`discord_ui.errors.OutOfValidRange` : The specified row was out of the possible range of the component rows
470470
471471
"""
472472
comps = []
@@ -529,7 +529,7 @@ async def wait_for(self, event_name: Literal["select", "button"], client, custom
529529
Parameters
530530
-----------
531531
event_name: :class:`str`
532-
The name of the event which will be awaited [``"select"`` | ``"button"``]
532+
The name of the event which will be awaited [``"select"`` | ``"button"``]
533533
534534
.. note::
535535

discord_ui/slash/types.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def __init__(self, argument_type, name, description=None, required=False, choice
4747
self._json = {}
4848
self.argument_type = argument_type
4949
self.name = name
50-
self.description = description or self.name
50+
self.description = _or(description, self.name)
5151
if required is True:
52-
self.required = required or []
53-
if options is not MISSING:
54-
self.options = options or []
55-
if choices is not MISSING:
52+
self.required = _default([], required)
53+
if not _none(options):
54+
self.options = _default([], options)
55+
if not _none(choices):
5656
self._json["choices"] = choices
5757
def __repr__(self) -> str:
5858
return f"<discord_ui.SlashOption({str(self.to_dict())})>"
@@ -121,7 +121,7 @@ def choices(self) -> typing.List[dict]:
121121
122122
.. note::
123123
124-
Choices are formated like this: ``[{"name": "name of the choice", "value": "the real value"}, ...]``
124+
Choices are formated like this: ``[{"name": "name of the choice", "value": "the real value"}, ...]``
125125
126126
:type: List[:class:`dict`]
127127
"""
@@ -256,7 +256,7 @@ def __init__(self, allowed: dict=MISSING, forbidden=MISSING) -> None:
256256
257257
Example
258258
```py
259-
SlashPermission(allowed=[
259+
SlashPermission(allowed=[
260260
await bot.fetch_user(bot.owner_id)
261261
], forbidden={
262262
539459006847255232: SlashPermission.User,
@@ -347,10 +347,7 @@ def __init__(self, callback, name=MISSING, description=MISSING, options=MISSING,
347347
"type": CommandType.SLASH
348348
}
349349

350-
# Check options before callback because callback makes an option check
351-
if options is MISSING:
352-
options = []
353-
self.options = options
350+
self.options = _default([], options)
354351
if callback is not None:
355352
if not inspect.iscoroutinefunction(callback):
356353
raise NoAsyncCallback()
@@ -410,7 +407,7 @@ def __eq__(self, o: object) -> bool:
410407
)
411408
elif isinstance(o, SlashCommand):
412409
return (
413-
o._json('type') == self._json["type"]
410+
o._json('type') == self._json["type"]
414411
and o.name == self.name
415412
and o.description == self.description
416413
and o.options == self.options
@@ -536,12 +533,12 @@ def __init__(self, callback, name=MISSING, description=MISSING, options=MISSING,
536533
async def my_function(command, parameter=None):
537534
pass
538535
539-
SlashCommand(callback=my_function, name="hello_world", description="This is a test command",
536+
SlashCommand(callback=my_function, name="hello_world", description="This is a test command",
540537
options=[
541538
SlashOption(str, name="parameter", description="this is a parameter", choices=[{ "name": "choice 1", "value": 1 }])
542-
], guild_ids=[785567635802816595], default_permission=False,
543-
guild_permissions={
544-
785567635802816595: SlashPermission(allowed={"539459006847254542": SlashPermission.USER})
539+
], guild_ids=[785567635802816595], default_permission=False,
540+
guild_permissions={
541+
785567635802816595: SlashPermission(allowed={"539459006847254542": SlashPermission.USER})
545542
})
546543
```
547544
"""

discord_ui/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, *args):
2020
def _none(*args, empty_array=False):
2121
return all(x in [None, MISSING] + [[], [[]]][empty_array is True] for x in args)
2222
def _or(*args, default=None):
23-
for i in range(len(args)):
23+
for i, _ in enumerate(args):
2424
if not _none(args[i]):
2525
return args[i]
2626
return default

examples/context_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Example by 404kuso
22
# https://github.com/discord-py-ui/discord-ui/tree/main/examples/context_commands.py
3-
#
3+
#
44
# This example will use the two new ui context commands,
55
# one will quote the message and one will send their avatar
66
# Note:

examples/generate_linkbutton.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Example by 404kuso
22
# https://github.com/discord-py-ui/discord-ui/tree/main/examples/generate_linkbutton.py
3-
#
3+
#
44
# This example will use a slash subcommand group and will generate a
55
# linkbutton with a name, link and emoji which the user can specify
66
# Note:
@@ -21,9 +21,9 @@
2121
# The user can specify the message content
2222
SlashOption(str, "message content", "the content of the message"),
2323
# The name of the linkbutton
24-
SlashOption(str, "name", "the name of the button"),
24+
SlashOption(str, "name", "the name of the button"),
2525
# The link of the linkbutton
26-
SlashOption(str, "link", "the link for the button"),
26+
SlashOption(str, "link", "the link for the button"),
2727
# The eomji of the linkbutton
2828
SlashOption(str, "emoji", "a emoji appearing before the text")
2929
],

examples/role_picker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# Note: For this example to work, the bot has to have the MANAGE_ROLES permission and the bot role
88
# has to be higher than the roles.
9-
# Also, if you want to test this, replace '785567635802816595' in guild_ids=[] with a guild id of
9+
# Also, if you want to test this, replace '785567635802816595' in guild_ids=[] with a guild id of
1010
# your choice, because guild slash commands are way faster than globals
1111
#
1212
# Replace '867715564155568158', '867715628504186911', '867715582903582743' and '867715674386071602'

0 commit comments

Comments
 (0)