Browse Source

Fix some type-check errors

pull/7494/head
Josh 3 years ago
committed by Rapptz
parent
commit
3ce00abeae
  1. 4
      discord/channel.py
  2. 2
      discord/flags.py
  3. 2
      discord/reaction.py
  4. 2
      discord/sticker.py
  5. 11
      discord/user.py
  6. 12
      discord/widget.py

4
discord/channel.py

@ -884,8 +884,8 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
self.video_quality_mode: VideoQualityMode = try_enum(VideoQualityMode, data.get('video_quality_mode', 1)) self.video_quality_mode: VideoQualityMode = try_enum(VideoQualityMode, data.get('video_quality_mode', 1))
self.category_id: Optional[int] = utils._get_as_snowflake(data, 'parent_id') self.category_id: Optional[int] = utils._get_as_snowflake(data, 'parent_id')
self.position: int = data['position'] self.position: int = data['position']
self.bitrate: int = data.get('bitrate') self.bitrate: int = data['bitrate']
self.user_limit: int = data.get('user_limit') self.user_limit: int = data['user_limit']
self._fill_overwrites(data) self._fill_overwrites(data)
@property @property

2
discord/flags.py

@ -59,7 +59,7 @@ class flag_value:
return self return self
return instance._has_flag(self.flag) return instance._has_flag(self.flag)
def __set__(self, instance: BF, value: bool) -> None: def __set__(self, instance: BaseFlags, value: bool) -> None:
instance._set_flag(self.flag, value) instance._set_flag(self.flag, value)
def __repr__(self): def __repr__(self):

2
discord/reaction.py

@ -87,7 +87,7 @@ class Reaction:
self.message: Message = message self.message: Message = message
self.emoji: Union[PartialEmoji, Emoji, str] = emoji or message._state.get_reaction_emoji(data['emoji']) self.emoji: Union[PartialEmoji, Emoji, str] = emoji or message._state.get_reaction_emoji(data['emoji'])
self.count: int = data.get('count', 1) self.count: int = data.get('count', 1)
self.me: bool = data.get('me') self.me: bool = data['me']
# TODO: typeguard # TODO: typeguard
def is_custom_emoji(self) -> bool: def is_custom_emoji(self) -> bool:

2
discord/sticker.py

@ -123,7 +123,7 @@ class StickerPack(Hashable):
@property @property
def banner(self) -> Optional[Asset]: def banner(self) -> Optional[Asset]:
""":class:`Asset`: The banner asset of the sticker pack.""" """:class:`Asset`: The banner asset of the sticker pack."""
return self._banner and Asset._from_sticker_banner(self._state, self._banner) return self._banner and Asset._from_sticker_banner(self._state, self._banner) # type: ignore - type-checker thinks _banner could be Literal[0]
def __repr__(self) -> str: def __repr__(self) -> str:
return f'<StickerPack id={self.id} name={self.name!r} description={self.description!r}>' return f'<StickerPack id={self.id} name={self.name!r} description={self.description!r}>'

11
discord/user.py

@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional, Type, TypeVar, TYPE_CHECKING from typing import Any, Dict, List, Optional, Union, Type, TypeVar, TYPE_CHECKING
import discord.abc import discord.abc
from .asset import Asset from .asset import Asset
@ -41,7 +41,10 @@ if TYPE_CHECKING:
from .message import Message from .message import Message
from .state import ConnectionState from .state import ConnectionState
from .types.channel import DMChannel as DMChannelPayload from .types.channel import DMChannel as DMChannelPayload
from .types.user import User as UserPayload from .types.user import (
PartialUser as PartialUserPayload,
User as UserPayload,
)
__all__ = ( __all__ = (
@ -83,7 +86,7 @@ class BaseUser(_UserTag):
_accent_colour: Optional[int] _accent_colour: Optional[int]
_public_flags: int _public_flags: int
def __init__(self, *, state: ConnectionState, data: UserPayload) -> None: def __init__(self, *, state: ConnectionState, data: Union[UserPayload, PartialUserPayload]) -> None:
self._state = state self._state = state
self._update(data) self._update(data)
@ -105,7 +108,7 @@ class BaseUser(_UserTag):
def __hash__(self) -> int: def __hash__(self) -> int:
return self.id >> 22 return self.id >> 22
def _update(self, data: UserPayload) -> None: def _update(self, data: Union[UserPayload, PartialUserPayload]) -> None:
self.name = data['username'] self.name = data['username']
self.id = int(data['id']) self.id = int(data['id'])
self.discriminator = data['discriminator'] self.discriminator = data['discriminator']

12
discord/widget.py

@ -23,6 +23,7 @@ DEALINGS IN THE SOFTWARE.
""" """
from __future__ import annotations from __future__ import annotations
from sqlite3 import connect
from typing import Any, List, Optional, TYPE_CHECKING, Union from typing import Any, List, Optional, TYPE_CHECKING, Union
@ -260,12 +261,13 @@ class Widget:
channels = {channel.id: channel for channel in self.channels} channels = {channel.id: channel for channel in self.channels}
for member in data.get('members', []): for member in data.get('members', []):
connected_channel = _get_as_snowflake(member, 'channel_id') connected_channel = _get_as_snowflake(member, 'channel_id')
if connected_channel in channels: if connected_channel is not None:
connected_channel = channels[connected_channel] # type: ignore if connected_channel in channels:
elif connected_channel: connected_channel = channels[connected_channel]
connected_channel = WidgetChannel(id=connected_channel, name='', position=0) else:
connected_channel = WidgetChannel(id=connected_channel, name='', position=0)
self.members.append(WidgetMember(state=self._state, data=member, connected_channel=connected_channel)) # type: ignore self.members.append(WidgetMember(state=self._state, data=member, connected_channel=connected_channel))
def __str__(self) -> str: def __str__(self) -> str:
return self.json_url return self.json_url

Loading…
Cancel
Save