Browse Source

Use Mapping instead of Dict for AuditLogEntry inner cache data

pull/9186/head
Rapptz 2 years ago
parent
commit
68c929cddf
  1. 20
      discord/audit_logs.py
  2. 2
      discord/state.py

20
discord/audit_logs.py

@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Generator, List, Optional, Tuple, Type, TypeVar, Union from typing import TYPE_CHECKING, Any, Callable, ClassVar, Mapping, Generator, List, Optional, Tuple, Type, TypeVar, Union
from . import enums, flags, utils from . import enums, flags, utils
from .asset import Asset from .asset import Asset
@ -315,7 +315,7 @@ Transformer = Callable[["AuditLogEntry", Any], Any]
class AuditLogChanges: class AuditLogChanges:
# fmt: off # fmt: off
TRANSFORMERS: ClassVar[Dict[str, Tuple[Optional[str], Optional[Transformer]]]] = { TRANSFORMERS: ClassVar[Mapping[str, Tuple[Optional[str], Optional[Transformer]]]] = {
'verification_level': (None, _enum_transformer(enums.VerificationLevel)), 'verification_level': (None, _enum_transformer(enums.VerificationLevel)),
'explicit_content_filter': (None, _enum_transformer(enums.ContentFilter)), 'explicit_content_filter': (None, _enum_transformer(enums.ContentFilter)),
'allow': (None, _flag_transformer(Permissions)), 'allow': (None, _flag_transformer(Permissions)),
@ -568,19 +568,19 @@ class AuditLogEntry(Hashable):
def __init__( def __init__(
self, self,
*, *,
users: Dict[int, User], users: Mapping[int, User],
integrations: Dict[int, PartialIntegration], integrations: Mapping[int, PartialIntegration],
app_commands: Dict[int, AppCommand], app_commands: Mapping[int, AppCommand],
automod_rules: Dict[int, AutoModRule], automod_rules: Mapping[int, AutoModRule],
data: AuditLogEntryPayload, data: AuditLogEntryPayload,
guild: Guild, guild: Guild,
): ):
self._state: ConnectionState = guild._state self._state: ConnectionState = guild._state
self.guild: Guild = guild self.guild: Guild = guild
self._users: Dict[int, User] = users self._users: Mapping[int, User] = users
self._integrations: Dict[int, PartialIntegration] = integrations self._integrations: Mapping[int, PartialIntegration] = integrations
self._app_commands: Dict[int, AppCommand] = app_commands self._app_commands: Mapping[int, AppCommand] = app_commands
self._automod_rules: Dict[int, AutoModRule] = automod_rules self._automod_rules: Mapping[int, AutoModRule] = automod_rules
self._from_data(data) self._from_data(data)
def _from_data(self, data: AuditLogEntryPayload) -> None: def _from_data(self, data: AuditLogEntryPayload) -> None:

2
discord/state.py

@ -1105,7 +1105,7 @@ class ConnectionState(Generic[ClientT]):
return return
entry = AuditLogEntry( entry = AuditLogEntry(
users=self._users, # type: ignore users=self._users,
integrations={}, integrations={},
app_commands={}, app_commands={},
automod_rules={}, automod_rules={},

Loading…
Cancel
Save