Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

https://img.shields.io/pypi/v/slotscheck.svg?color=blue https://img.shields.io/pypi/l/slotscheck.svg https://img.shields.io/pypi/pyversions/slotscheck.svg https://img.shields.io/readthedocs/slotscheck.svg https://github.com/ariebovenberg/slotscheck/actions/workflows/build.yml/badge.svg https://img.shields.io/badge/coverage-100%25-forestgreen?style=flat-square

Adding __slots__ to a class in Python is a great way to improve performance. But to work properly, all base classes need to implement it — without overlap! It’s easy to get wrong, and what’s worse: there is nothing warning you that you messed up.

Until now!

slotscheck helps you validate your slots are working properly. You can even use it to enforce the use of slots across (parts of) your codebase.

See my talk at EuroPython for the details of how slots work and what can go wrong with them.

Quickstart

Usage is quick from the command line:

python -m slotscheck [FILES]...
# or
slotscheck -m [MODULES]...

For example:

$ slotscheck -m sanic
ERROR: 'sanic.app:Sanic' defines overlapping slots.
ERROR: 'sanic.response:HTTPResponse' has slots but superclass does not.
Oh no, found some problems!
Scanned 72 module(s), 111 class(es).

Now get to fixing — and add slotscheck to your CI pipeline or pre-commit to prevent mistakes from creeping in again! See here and here for examples.

Features

  • Detect broken slots inheritance

  • Detect overlapping slots

  • Detect duplicate slots

  • Pre-commit hook

  • (Optionally) enforce the use of slots

See the documentation for more details and configuration options.

Why not a flake8 plugin?

Flake8 plugins need to work without running the code. Many libraries use conditional imports, star imports, re-exports, and define slots with decorators or metaclasses. This all but requires running the code to determine the slots and class tree.

There’s an issue to discuss the matter.

Why not pylint or ruff?

Pylint and Ruff do have some checks related to __slots__, but they are still static analyzers. They cannot see slots that are computed at import time—or follow deep inheritance trees, which are common in real code. People often generate slots automatically when optimizing class hierarchies, and frameworks like dataclasses, attrs, and pydantic also generate slots for you. slotscheck runs the code and inspects the resulting class tree, and it can also detect unused slots. Ruff and Pylint can still catch some more basic slot mistakes, such as invalid __slots__ declarations.

Notes

  • slotscheck does not work on alternative Python implementations such as PyPy, Jython, or IronPython. This is for two reasons:

    1. Other implementations such as PyPy handle slots differently, and running slotscheck wouldn’t be useful.

    2. To perform its checks, slotscheck uses CPython-specific features

  • slotscheck will try to import all submodules of the given package. If there are scripts without if __name__ == "__main__": blocks, they may be executed.

  • Even in the case that slots are not inherited properly, there may still be an advantage to using them (i.e. attribute access speed and some memory savings). However, in most cases this is unintentional. slotscheck allows you to ignore specific cases.

  • Because slotscheck imports your code in arbitrary order, it can—in rare cases—result in confusing and randomly-occurring import errors in third-party libraries. In such a case, it is recommended to omit modules such as your tests and mypy plugins from the slotscheck run. See here. Alternatively, you can use PYTHONHASHSEED=<any value> to make the import order deterministic. A solution to this problem is being worked on in this issue.

Installation

It’s available on PyPI.

pip install slotscheck

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slotscheck-0.21.0b1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slotscheck-0.21.0b1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file slotscheck-0.21.0b1.tar.gz.

File metadata

  • Download URL: slotscheck-0.21.0b1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for slotscheck-0.21.0b1.tar.gz
Algorithm Hash digest
SHA256 64f38078ff02b6e9e5ecfda9f03d41f879dab0c65e9e286ed739754fa569fd9a
MD5 2041acdc72e260159f760e0e16371691
BLAKE2b-256 a97ca02b29f0c6c73fbef950347e244fb16efe4700aa6386cbd10e4ef44643ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for slotscheck-0.21.0b1.tar.gz:

Publisher: build.yml on ariebovenberg/slotscheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slotscheck-0.21.0b1-py3-none-any.whl.

File metadata

  • Download URL: slotscheck-0.21.0b1-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for slotscheck-0.21.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e23fa46942e42cba4fc1c2d05c91a396f58686fbe6b8e6a881ed24cc31e6b8f
MD5 1accbc9f8a03063ee833bc3a97d8f725
BLAKE2b-256 1c652aef243ccfbdee442b90db6e6d62a464f99d617396d6d758c7f7e221cb39

See more details on using hashes here.

Provenance

The following attestation bundles were made for slotscheck-0.21.0b1-py3-none-any.whl:

Publisher: build.yml on ariebovenberg/slotscheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.21.0

2 files

This release

0.21.0b1 This release

2 files

0.20.1

2 files

0.20.0

2 files

0.19.1

2 files

0.19.0

2 files

0.18.0

2 files

0.17.3

2 files

0.17.2

2 files

0.17.1

2 files

0.17.0

2 files

0.16.5

2 files

0.16.4

2 files

0.16.3

2 files

0.16.2

2 files

0.16.1

2 files

0.16.0

2 files

0.15.0

2 files

0.14.1

2 files

0.14.0

2 files

0.13.0

2 files

0.12.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page