Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def category(self) -> Optional[CategoryChannel]:
"""
if isinstance(self.guild, Object):
return None
return self.guild.get_channel(self.category_id) # type: ignore
return self.guild.get_channel(self.category_id) # pyright: ignore[reportArgumentType, reportReturnType]

@property
def permissions_synced(self) -> bool:
Expand Down Expand Up @@ -1082,7 +1082,7 @@ async def _clone_impl(
obj = cls(state=self._state, guild=self.guild, data=data)

# temporarily add it to the cache
self.guild._channels[obj.id] = obj # type: ignore
self.guild._channels[obj.id] = obj # pyright: ignore[reportArgumentType]
return obj

async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> Self:
Expand Down
26 changes: 13 additions & 13 deletions disnake/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ def __repr__(self) -> str:
inner = " ".join(f"{k!s}={v!r}" for k, v in attrs)
return f"<Activity {inner}>"

def to_dict(self) -> Dict[str, Any]:
ret: Dict[str, Any] = {}
def to_dict(self) -> ActivityPayload:
ret: ActivityPayload = {} # pyright: ignore[reportAssignmentType]
for attr in self.__slots__:
value = getattr(self, attr, None)
if value is None:
Expand All @@ -408,16 +408,16 @@ def to_dict(self) -> Dict[str, Any]:
if isinstance(value, dict) and len(value) == 0:
continue

ret[attr] = value
ret[attr] = value # pyright: ignore[reportGeneralTypeIssues]

# fix type field
ret["type"] = int(self.type)
ret["type"] = int(self.type) # pyright: ignore[reportGeneralTypeIssues] # ActivityPayload.type does not include -1

if self.status_display_type:
ret["status_display_type"] = int(self.status_display_type)
ret["status_display_type"] = int(self.status_display_type) # pyright: ignore[reportGeneralTypeIssues]

if self.emoji:
ret["emoji"] = self.emoji.to_dict()
ret["emoji"] = self.emoji.to_dict() # pyright: ignore[reportGeneralTypeIssues]
# defined in base class slots
if self._timestamps:
ret["timestamps"] = self._timestamps
Expand Down Expand Up @@ -608,8 +608,8 @@ def twitch_name(self) -> Optional[str]:
name = self.assets["large_image"]
return name[7:] if name[:7] == "twitch:" else None

def to_dict(self) -> Dict[str, Any]:
ret: Dict[str, Any] = {
def to_dict(self) -> ActivityPayload:
ret: ActivityPayload = {
"type": ActivityType.streaming.value,
"name": str(self.name),
"url": str(self.url),
Expand Down Expand Up @@ -891,7 +891,7 @@ def to_dict(self) -> ActivityPayload:
}

if self.emoji:
o["emoji"] = self.emoji.to_dict() # type: ignore
o["emoji"] = self.emoji.to_dict() # pyright: ignore[reportGeneralTypeIssues]
return o

def __eq__(self, other: Any) -> bool:
Expand Down Expand Up @@ -945,16 +945,16 @@ def create_activity(
if game_type is ActivityType.playing and not (
"application_id" in data or "session_id" in data or "state" in data
):
activity = Game(**data) # type: ignore # pyright bug(?)
activity = Game(**data) # pyright: ignore[reportArgumentType] # pyright bug(?)
elif game_type is ActivityType.custom and "name" in data:
activity = CustomActivity(**data) # type: ignore
activity = CustomActivity(**data) # pyright: ignore[reportArgumentType]
elif game_type is ActivityType.streaming and "url" in data:
# url won't be None here
activity = Streaming(**data) # type: ignore
activity = Streaming(**data) # pyright: ignore[reportArgumentType]
elif game_type is ActivityType.listening and "sync_id" in data and "session_id" in data:
activity = Spotify(**data)
else:
activity = Activity(**data) # type: ignore
activity = Activity(**data) # pyright: ignore[reportArgumentType]

if isinstance(activity, (Activity, CustomActivity)) and activity.emoji and state:
activity.emoji._state = state
Expand Down
4 changes: 2 additions & 2 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,13 +1254,13 @@ def __init__(self, *, data: ApplicationCommandPermissionsPayload, guild_id: int)
def __repr__(self) -> str:
return f"<ApplicationCommandPermissions id={self.id!r} type={self.type!r} permission={self.permission!r}>"

def __eq__(self, other) -> bool:
def __eq__(self, other: ApplicationCommandPermissions) -> bool:
return (
self.id == other.id and self.type == other.type and self.permission == other.permission
)

def to_dict(self) -> ApplicationCommandPermissionsPayload:
return {"id": self.id, "type": int(self.type), "permission": self.permission} # type: ignore
return {"id": self.id, "type": self.type.value, "permission": self.permission}

def is_everyone(self) -> bool:
"""Whether this permission object is affecting the @everyone role.
Expand Down
19 changes: 12 additions & 7 deletions disnake/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ def _transform_icon(entry: AuditLogEntry, data: Optional[str]) -> Optional[Asset
if data is None:
return None
if entry.action.name.startswith("role_"):
return Asset._from_role_icon(entry._state, entry._target_id, data) # type: ignore
assert entry._target_id is not None
return Asset._from_role_icon(entry._state, entry._target_id, data)
return Asset._from_guild_icon(entry._state, entry.guild.id, data)


def _transform_avatar(entry: AuditLogEntry, data: Optional[str]) -> Optional[Asset]:
if data is None:
return None
return Asset._from_avatar(entry._state, entry._target_id, data) # type: ignore
assert entry._target_id is not None
return Asset._from_avatar(entry._state, entry._target_id, data)


def _guild_hash_transformer(path: str) -> Callable[[AuditLogEntry, Optional[str]], Optional[Asset]]:
Expand Down Expand Up @@ -260,7 +262,8 @@ def _transform_guild_scheduled_event_image(
) -> Optional[Asset]:
if data is None:
return None
return Asset._from_guild_scheduled_event_image(entry._state, entry._target_id, data) # type: ignore
assert entry._target_id is not None
return Asset._from_guild_scheduled_event_image(entry._state, entry._target_id, data)


def _transform_automod_action(
Expand Down Expand Up @@ -378,10 +381,12 @@ def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]) -> N

# special cases for role add/remove
if attr == "$add":
self._handle_role(self.before, self.after, entry, elem["new_value"]) # type: ignore
assert "new_value" in elem
self._handle_role(self.before, self.after, entry, elem["new_value"]) # pyright: ignore[reportArgumentType]
continue
elif attr == "$remove":
self._handle_role(self.after, self.before, entry, elem["new_value"]) # type: ignore
assert "new_value" in elem
self._handle_role(self.after, self.before, entry, elem["new_value"]) # pyright: ignore[reportArgumentType]
continue

# special case for application command permissions update
Expand Down Expand Up @@ -454,7 +459,7 @@ def _handle_role(

if role is None:
role = Object(id=role_id)
role.name = e["name"] # type: ignore
role.name = e["name"] # pyright: ignore[reportAttributeAccessIssue]

data.append(role)

Expand Down Expand Up @@ -647,7 +652,7 @@ def _from_data(self, data: AuditLogEntryPayload) -> None:
role = self.guild.get_role(instance_id)
if role is None:
role = Object(id=instance_id)
role.name = extra.get("role_name") # type: ignore
role.name = extra.get("role_name") # pyright: ignore[reportAttributeAccessIssue]
self.extra = role
elif self.action.name.startswith("stage_instance"):
elems = {
Expand Down
10 changes: 5 additions & 5 deletions disnake/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def with_changes(
:class:`AutoModTriggerMetadata`
The new metadata instance.
"""
return self.__class__( # type: ignore # call doesn't match any overloads
return self.__class__(
keyword_filter=self.keyword_filter if keyword_filter is MISSING else keyword_filter,
regex_patterns=self.regex_patterns if regex_patterns is MISSING else regex_patterns,
presets=self.presets if presets is MISSING else presets,
Expand All @@ -368,7 +368,7 @@ def with_changes(
if mention_raid_protection_enabled is MISSING
else mention_raid_protection_enabled
),
)
) # pyright: ignore[reportCallIssue] # call doesn't match any overloads

@classmethod
def _from_dict(cls, data: AutoModTriggerMetadataPayload) -> Self:
Expand All @@ -377,14 +377,14 @@ def _from_dict(cls, data: AutoModTriggerMetadataPayload) -> Self:
else:
presets = None

return cls( # type: ignore # call doesn't match any overloads
return cls(
keyword_filter=data.get("keyword_filter"),
regex_patterns=data.get("regex_patterns"),
presets=presets,
allow_list=data.get("allow_list"),
mention_total_limit=data.get("mention_total_limit"),
mention_raid_protection_enabled=data.get("mention_raid_protection_enabled"),
)
) # pyright: ignore[reportCallIssue] # call doesn't match any overloads

def to_dict(self) -> AutoModTriggerMetadataPayload:
data: AutoModTriggerMetadataPayload = {}
Expand All @@ -393,7 +393,7 @@ def to_dict(self) -> AutoModTriggerMetadataPayload:
if self.regex_patterns is not None:
data["regex_patterns"] = list(self.regex_patterns)
if self.presets is not None:
data["presets"] = self.presets.values # type: ignore # `values` contains ints instead of preset literal values
data["presets"] = self.presets.values # pyright: ignore[reportGeneralTypeIssues] # `values` contains ints instead of preset literal values
if self.allow_list is not None:
data["allow_list"] = list(self.allow_list)
if self.mention_total_limit is not None:
Expand Down
29 changes: 14 additions & 15 deletions disnake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, *, data: VoiceChannelEffectPayload, state: ConnectionState) -
else:
sound_data: PartialSoundboardSoundPayload = {
"sound_id": sound_id,
"volume": data.get("sound_volume"), # type: ignore # assume this exists if sound_id is set
"volume": data.get("sound_volume"), # pyright: ignore[reportAssignmentType] # assume this exists if sound_id is set
}
self.sound = PartialSoundboardSound(data=sound_data, state=state)

Expand Down Expand Up @@ -547,7 +547,7 @@ async def edit(
)
if payload is not None:
# the payload will always be the proper channel payload
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
return self.__class__(state=self._state, guild=self.guild, data=payload) # pyright: ignore[reportArgumentType]

async def clone(
self,
Expand Down Expand Up @@ -1091,25 +1091,22 @@ async def create_thread(
:class:`Thread`
The newly created thread
"""
if not ((message is None) ^ (type is None)):
raise ValueError("Exactly one of message and type must be provided.")

if auto_archive_duration is not None:
auto_archive_duration = cast(
"ThreadArchiveDurationLiteral", try_enum_to_int(auto_archive_duration)
)

if message is None:
if message is None and type is not None:
data = await self._state.http.start_thread_without_message(
self.id,
name=name,
auto_archive_duration=auto_archive_duration or self.default_auto_archive_duration,
type=type.value, # type: ignore
type=type.value,
invitable=invitable if invitable is not None else True,
rate_limit_per_user=slowmode_delay,
reason=reason,
)
else:
elif message is not None and type is None:
data = await self._state.http.start_thread_with_message(
self.id,
message.id,
Expand All @@ -1118,6 +1115,8 @@ async def create_thread(
rate_limit_per_user=slowmode_delay,
reason=reason,
)
else:
raise ValueError("Exactly one of message and type must be provided.")

return Thread(guild=self.guild, state=self._state, data=data)

Expand Down Expand Up @@ -1706,7 +1705,7 @@ async def edit(
)
if payload is not None:
# the payload will always be the proper channel payload
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
return self.__class__(state=self._state, guild=self.guild, data=payload) # pyright: ignore[reportArgumentType]

async def delete_messages(self, messages: Iterable[Snowflake]) -> None:
"""|coro|
Expand Down Expand Up @@ -2561,7 +2560,7 @@ async def edit(
)
if payload is not None:
# the payload will always be the proper channel payload
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
return self.__class__(state=self._state, guild=self.guild, data=payload) # pyright: ignore[reportArgumentType]

async def delete_messages(self, messages: Iterable[Snowflake]) -> None:
"""|coro|
Expand Down Expand Up @@ -3052,7 +3051,7 @@ async def edit(
)
if payload is not None:
# the payload will always be the proper channel payload
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
return self.__class__(state=self._state, guild=self.guild, data=payload) # pyright: ignore[reportArgumentType]

@overload
async def move(
Expand Down Expand Up @@ -3462,7 +3461,7 @@ def last_thread(self) -> Optional[Thread]:
Optional[:class:`Thread`]
The last created thread in this channel or ``None`` if not found.
"""
return self._state.get_channel(self.last_thread_id) if self.last_thread_id else None # type: ignore
return self._state.get_channel(self.last_thread_id) if self.last_thread_id else None # pyright: ignore[reportReturnType]

@property
def available_tags(self) -> List[ForumTag]:
Expand Down Expand Up @@ -4208,7 +4207,7 @@ async def edit(
)
if payload is not None:
# the payload will always be the proper channel payload
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
return self.__class__(state=self._state, guild=self.guild, data=payload) # pyright: ignore[reportArgumentType]

async def clone(
self,
Expand Down Expand Up @@ -4606,7 +4605,7 @@ async def edit(
)
if payload is not None:
# the payload will always be the proper channel payload
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
return self.__class__(state=self._state, guild=self.guild, data=payload) # pyright: ignore[reportArgumentType]

async def clone(
self,
Expand Down Expand Up @@ -4780,7 +4779,7 @@ def __init__(self, *, me: ClientUser, state: ConnectionState, data: DMChannelPay
self._state: ConnectionState = state
self.recipient: Optional[User] = None
if recipients := data.get("recipients"):
self.recipient = state.store_user(recipients[0]) # type: ignore
self.recipient = state.store_user(recipients[0]) # pyright: ignore[reportArgumentType]

self.me: ClientUser = me
self.id: int = int(data["id"])
Expand Down
Loading