Slotscheck

0.19.1 · active · verified Fri Apr 17

Slotscheck is a Python library that helps ensure your `__slots__` are working properly. It acts as a linter, identifying classes where `__slots__` might not be effective or are misused, thereby aiding in memory optimization and performance. The current version is 0.19.1, and it has a regular release cadence, often aligning with new Python versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use the `slotscheck` function to verify `__slots__` implementation for individual classes. It shows examples of both a correctly slotted and an unslotted class, and how to get results from the checker. It can also be used to check entire modules.

from slotscheck import slotscheck

class MySlottedClass:
    __slots__ = ('x', 'y')

    def __init__(self, x, y):
        self.x = x
        self.y = y

class MyUnslottedClass:
    def __init__(self, x, y):
        self.x = x
        self.y = y

results_slotted = slotscheck(MySlottedClass)
print(f"MySlottedClass check results: {results_slotted}")

results_unslotted = slotscheck(MyUnslottedClass)
print(f"MyUnslottedClass check results: {results_unslotted}")

# To check an entire module (e.g., the current file):
# import sys
# current_module = sys.modules[__name__]
# module_results = slotscheck(current_module)
# print(f"Current module check results: {module_results}")

view raw JSON →