Skip to content

feat: ✨ Add slotscheck to ensure __slots__ are used correctly #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions .github/workflows/lib-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,21 @@ jobs:
run: mkdir -p -v .mypy_cache
- name: "Run mypy"
run: uv run mypy --non-interactive discord/
slotscheck:
if: ${{ github.event_name != 'schedule' }}
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: "Install uv"
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- name: Sync dependencies
run: uv sync --no-python-downloads --group dev
- name: "Run slotscheck"
run: uv run slotscheck discord
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ repos:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
exclude: \.(po|pot|yml|yaml)$
- repo: https://github.com/ariebovenberg/slotscheck
rev: v0.19.1
hooks:
- id: slotscheck
additional_dependencies:
- "typing-extensions>=4,<5"
- "colorlog~=6.9.0"
- "aiohttp>=3.6.0,<4.0"
1 change: 0 additions & 1 deletion discord/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ class Activity(BaseActivity):
__slots__ = (
"state",
"details",
"_created_at",
"timestamps",
"assets",
"party",
Expand Down
3 changes: 2 additions & 1 deletion discord/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class AssetMixin:
url: str
_state: Any | None

__slots__: tuple[str, ...] = ("_state", "url")

async def read(self) -> bytes:
"""|coro|

Expand Down Expand Up @@ -148,7 +150,6 @@ class Asset(AssetMixin):
"""

__slots__: tuple[str, ...] = (
"_state",
"_url",
"_animated",
"_key",
Expand Down
1 change: 0 additions & 1 deletion discord/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ class InputText(Component):
"""

__slots__: tuple[str, ...] = (
"type",
"style",
"custom_id",
"label",
Expand Down
2 changes: 0 additions & 2 deletions discord/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ class BaseEmoji(_EmojiTag, AssetMixin):
"require_colons",
"animated",
"managed",
"id",
"name",
"_state",
"user",
"available",
)
Expand Down
2 changes: 1 addition & 1 deletion discord/partial_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class PartialEmoji(_EmojiTag, AssetMixin):
The ID of the custom emoji, if applicable.
"""

__slots__ = ("animated", "name", "id", "_state")
__slots__ = ("animated", "name", "id")

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

Expand Down
2 changes: 2 additions & 0 deletions discord/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@


class _RawReprMixin:
__slots__ = ()

def __repr__(self) -> str:
value = " ".join(f"{attr}={getattr(self, attr)!r}" for attr in self.__slots__)
return f"<{self.__class__.__name__} {value}>"
Expand Down
4 changes: 2 additions & 2 deletions discord/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class StickerItem(_StickerTag):
The URL for the sticker's image.
"""

__slots__ = ("_state", "name", "id", "format", "url")
__slots__ = ("name", "id", "format")

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

__slots__ = ("_state", "id", "name", "description", "format", "url")
__slots__ = ("id", "name", "description", "format")

def __init__(self, *, state: ConnectionState, data: StickerPayload) -> None:
self._state: ConnectionState = state
Expand Down
4 changes: 0 additions & 4 deletions discord/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,9 @@ class WidgetMember(BaseUser):
"""

__slots__ = (
"name",
"status",
"nick",
"avatar",
"discriminator",
"id",
"bot",
"activity",
"deafened",
"suppress",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ dev = [
"pytest~=8.3.5",
"pytest-asyncio~=0.24.0",
"ruff>=0.11.9",
"slotscheck>=0.19.1",
]

[tool.hatch.version]
Expand Down
15 changes: 15 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.