Fix code style issues with Black

This commit is contained in:
Lint Action
2021-09-05 21:34:20 +00:00
parent a23dae8604
commit 7513c2138f
108 changed files with 5369 additions and 4858 deletions

View File

@@ -41,9 +41,7 @@ from ..components import (
SelectMenu as SelectComponent,
)
__all__ = (
'View',
)
__all__ = ("View",)
if TYPE_CHECKING:
@@ -74,9 +72,7 @@ def _component_to_item(component: Component) -> Item:
class _ViewWeights:
__slots__ = (
'weights',
)
__slots__ = ("weights",)
def __init__(self, children: List[Item]):
self.weights: List[int] = [0, 0, 0, 0, 0]
@@ -92,13 +88,13 @@ class _ViewWeights:
if weight + item.width <= 5:
return index
raise ValueError('could not find open space for item')
raise ValueError("could not find open space for item")
def add_item(self, item: Item) -> None:
if item.row is not None:
total = self.weights[item.row] + item.width
if total > 5:
raise ValueError(f'item would not fit at row {item.row} ({total} > 5 width)')
raise ValueError(f"item would not fit at row {item.row} ({total} > 5 width)")
self.weights[item.row] = total
item._rendered_row = item.row
else:
@@ -144,11 +140,11 @@ class View:
children: List[ItemCallbackType] = []
for base in reversed(cls.__mro__):
for member in base.__dict__.values():
if hasattr(member, '__discord_ui_model_type__'):
if hasattr(member, "__discord_ui_model_type__"):
children.append(member)
if len(children) > 25:
raise TypeError('View cannot have more than 25 children')
raise TypeError("View cannot have more than 25 children")
cls.__view_children_items__ = children
@@ -171,7 +167,7 @@ class View:
self.__stopped: asyncio.Future[bool] = loop.create_future()
def __repr__(self) -> str:
return f'<{self.__class__.__name__} timeout={self.timeout} children={len(self.children)}>'
return f"<{self.__class__.__name__} timeout={self.timeout} children={len(self.children)}>"
async def __timeout_task_impl(self) -> None:
while True:
@@ -203,8 +199,8 @@ class View:
components.append(
{
'type': 1,
'components': children,
"type": 1,
"components": children,
}
)
@@ -261,10 +257,10 @@ class View:
"""
if len(self.children) > 25:
raise ValueError('maximum number of children exceeded')
raise ValueError("maximum number of children exceeded")
if not isinstance(item, Item):
raise TypeError(f'expected Item not {item.__class__!r}')
raise TypeError(f"expected Item not {item.__class__!r}")
self.__weights.add_item(item)
@@ -344,7 +340,7 @@ class View:
interaction: :class:`~discord.Interaction`
The interaction that led to the failure.
"""
print(f'Ignoring exception in view {self} for item {item}:', file=sys.stderr)
print(f"Ignoring exception in view {self} for item {item}:", file=sys.stderr)
traceback.print_exception(error.__class__, error, error.__traceback__, file=sys.stderr)
async def _scheduled_task(self, item: Item, interaction: Interaction):
@@ -377,13 +373,13 @@ class View:
return
self.__stopped.set_result(True)
asyncio.create_task(self.on_timeout(), name=f'discord-ui-view-timeout-{self.id}')
asyncio.create_task(self.on_timeout(), name=f"discord-ui-view-timeout-{self.id}")
def _dispatch_item(self, item: Item, interaction: Interaction):
if self.__stopped.done():
return
asyncio.create_task(self._scheduled_task(item, interaction), name=f'discord-ui-view-dispatch-{self.id}')
asyncio.create_task(self._scheduled_task(item, interaction), name=f"discord-ui-view-dispatch-{self.id}")
def refresh(self, components: List[Component]):
# This is pretty hacky at the moment