Skip to main content
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/codecov/c/github/ariebovenberg/slotscheck.svg https://img.shields.io/badge/code%20style-black-000000.svg

Adding __slots__ to a class in Python is a great way to reduce memory usage. 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 blog post for the origin story behind slotscheck.

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 to prevent mistakes from creeping in again! See here and here for examples.

Features

  • Detect broken slots inheritance

  • Detect overlapping 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.

Notes

  • 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.

  • Non pure-Python classes are currently assumed to have slots. This is not necessarily the case, but it is nontrivial to determine.

Installation

It’s available on PyPI.

pip install slotscheck

Release files for slotscheck 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slotscheck 0.10.0
File Size Uploaded
slotscheck-0.10.0.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slotscheck 0.10.0
File Interpreter ABI Platform
slotscheck-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.3 kB

Release files / slotscheck-0.10.0.tar.gz

Download URL slotscheck-0.10.0.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8307549d0b152a3ac7a05e081b85d18aa2897759c0a6866a4ad69e86e9010056
BLAKE2b-256 checksum
How to use checksums
dfae1d4b583c8d4d1ccffd4675c375e4c330bdc99714a7301cff8847569e94c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.9.9 Darwin/21.3.0

Release files / slotscheck-0.10.0-py3-none-any.whl

Download URL slotscheck-0.10.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4476edecfd42a2b8934d32cc0c660e015220d5a2b5c753c8bdac569ee7c4d621
BLAKE2b-256 checksum
How to use checksums
758c043cb62101fae5cb9db62e14010801f38376389d51bb6009d1a050289a7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.9.9 Darwin/21.3.0

Release history Release notifications | RSS feed

0.20.0

2 release files

0.19.1

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.4

2 release files

0.16.2

2 release files

0.16.1

2 release files

0.16.0

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.1

2 release files

0.10.2

2 release files

0.10.1

2 release files

This release

0.10.0 This release

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release 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