Skip to content

Commit 8c5c945

Browse files
committed
✨ Add slotscheck to ensure __slots__ are used correctly
1 parent 2078cef commit 8c5c945

File tree

12 files changed

+49
-12
lines changed

12 files changed

+49
-12
lines changed

.github/workflows/lib-checks.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,21 @@ jobs:
9393
run: mkdir -p -v .mypy_cache
9494
- name: "Run mypy"
9595
run: uv run mypy --non-interactive discord/
96+
slotscheck:
97+
if: ${{ github.event_name != 'schedule' }}
98+
runs-on: ubuntu-latest
99+
steps:
100+
- name: "Checkout Repository"
101+
uses: actions/checkout@v4
102+
- name: "Setup Python"
103+
uses: actions/setup-python@v5
104+
with:
105+
python-version: "3.13"
106+
- name: "Install uv"
107+
uses: astral-sh/setup-uv@v6
108+
with:
109+
enable-cache: true
110+
- name: Sync dependencies
111+
run: uv sync --no-python-downloads --group dev
112+
- name: "Run slotscheck"
113+
run: uv run slotscheck discord

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ repos:
3333
- id: prettier
3434
args: [--prose-wrap=always, --print-width=88]
3535
exclude: \.(po|pot|yml|yaml)$
36+
- repo: https://github.com/ariebovenberg/slotscheck
37+
rev: v0.19.1
38+
hooks:
39+
- id: slotscheck
40+
additional_dependencies:
41+
- "typing-extensions>=4,<5"
42+
- "colorlog~=6.9.0"
43+
- "aiohttp>=3.6.0,<4.0"

discord/activity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ class Activity(BaseActivity):
204204
__slots__ = (
205205
"state",
206206
"details",
207-
"_created_at",
208207
"timestamps",
209208
"assets",
210209
"party",

discord/asset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class AssetMixin:
5151
url: str
5252
_state: Any | None
5353

54+
__slots__: tuple[str, ...] = ("_state", "url")
55+
5456
async def read(self) -> bytes:
5557
"""|coro|
5658
@@ -148,7 +150,6 @@ class Asset(AssetMixin):
148150
"""
149151

150152
__slots__: tuple[str, ...] = (
151-
"_state",
152153
"_url",
153154
"_animated",
154155
"_key",

discord/components.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ class InputText(Component):
154154
"""
155155

156156
__slots__: tuple[str, ...] = (
157-
"type",
158157
"style",
159158
"custom_id",
160159
"label",

discord/emoji.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ class BaseEmoji(_EmojiTag, AssetMixin):
5353
"require_colons",
5454
"animated",
5555
"managed",
56-
"id",
5756
"name",
58-
"_state",
5957
"user",
6058
"available",
6159
)

discord/partial_emoji.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class PartialEmoji(_EmojiTag, AssetMixin):
9191
The ID of the custom emoji, if applicable.
9292
"""
9393

94-
__slots__ = ("animated", "name", "id", "_state")
94+
__slots__ = ("animated", "name", "id")
9595

9696
_CUSTOM_EMOJI_RE = re.compile(r"<?(?P<animated>a)?:?(?P<name>\w+):(?P<id>[0-9]{13,20})>?")
9797

discord/raw_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585

8686

8787
class _RawReprMixin:
88+
__slots__ = ()
89+
8890
def __repr__(self) -> str:
8991
value = " ".join(f"{attr}={getattr(self, attr)!r}" for attr in self.__slots__)
9092
return f"<{self.__class__.__name__} {value}>"

discord/sticker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class StickerItem(_StickerTag):
200200
The URL for the sticker's image.
201201
"""
202202

203-
__slots__ = ("_state", "name", "id", "format", "url")
203+
__slots__ = ("name", "id", "format")
204204

205205
def __init__(self, *, state: ConnectionState, data: StickerItemPayload):
206206
self._state: ConnectionState = state
@@ -271,7 +271,7 @@ class Sticker(_StickerTag):
271271
The URL for the sticker's image.
272272
"""
273273

274-
__slots__ = ("_state", "id", "name", "description", "format", "url")
274+
__slots__ = ("id", "name", "description", "format")
275275

276276
def __init__(self, *, state: ConnectionState, data: StickerPayload) -> None:
277277
self._state: ConnectionState = state

discord/widget.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,9 @@ class WidgetMember(BaseUser):
152152
"""
153153

154154
__slots__ = (
155-
"name",
156155
"status",
157156
"nick",
158157
"avatar",
159-
"discriminator",
160-
"id",
161-
"bot",
162158
"activity",
163159
"deafened",
164160
"suppress",

0 commit comments

Comments
 (0)