Slotscheck - Find mistakes in your slots definitions

Overview

🎰 Slotscheck

https://img.shields.io/pypi/v/slotscheck.svg?color=blue

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. It turns out it's easy to forget one class in complex inheritance trees. What's worse: there is nothing warning you that you messed up.

Until now!

See my blog post for the longer story behind slotscheck.

Quickstart

Usage is quick from the command line:

slotscheck [MODULE]

For example:

$ slotscheck pandas
ERROR: 'pandas.core.internals.array_manager.SingleArrayManager' has slots but inherits from non-slot class
ERROR: 'pandas.core.internals.blocks.Block' has slots but inherits from non-slot class
ERROR: 'pandas.core.internals.blocks.NumericBlock' has slots but inherits from non-slot class
ERROR: 'pandas.core.internals.blocks.DatetimeLikeBlock' has slots but inherits from non-slot class
ERROR: 'pandas.core.internals.blocks.ObjectBlock' has slots but inherits from non-slot class
ERROR: 'pandas.core.internals.blocks.CategoricalBlock' has slots but inherits from non-slot class
ERROR: 'pandas.core.internals.array_manager.BaseArrayManager' has slots but inherits from non-slot class
ERROR: 'pandas.core.internals.managers.BaseBlockManager' has slots but inherits from non-slot class
ERROR: 'pandas.core.internals.managers.SingleBlockManager' has slots but inherits from non-slot class

Now get to fixing -- and add slotscheck to your CI pipeline to prevent mistakes from creeping in again!

Use the --help option to find out more.

Could this be a flake8 plugin?

Maybe. But it'd be a lot of work.

The problem is that flake8 plugins need to work without running the code. Many libraries define conditional imports, star imports, re-exports or metaclasses which basically require running the code to find out the class tree.

There's an issue to track any progress on 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, I've found in most cases this is unintentional.
  • Only classes at module-level are checked (i.e. no nested classes)
  • In rare cases imports may fail, the module is then skipped. Use the verbose mode to show detailed information.
  • Limited to the CPython implementation for now.
  • 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
Owner
Arie Bovenberg
Dutch-American 🚲 civil engineer turned coder. Experienced python wrangler 🐍, functional-programming enthousiast ⚡, and aspiring computational wizard ✨.
Arie Bovenberg
Linux Pressure Stall Information (PSI) Status App

Linux Pressure Stall Information (PSI) Status App psistat is a simple python3 program to display the PSIs and to capture/display exception events. psi

Joe D 3 Sep 18, 2022
Make pack up python files easier.

python-easy-pack make pack up python files easier. 目前只提供了中文环境 如何使用? 将index.py复制到你的项目文件夹,或者把.py文件拷贝到这个文件夹。 打开你的cmd或者powershell 切换到程序所在目录,输入python index

2 Dec 15, 2021
Entitlement AND Hardened Runtime Check

Python3 script for macOS to recursively check /Applications and also check /usr/local/bin, /usr/bin, and /usr/sbin for binaries with problematic/interesting entitlements. Also checks for hardened run

Cedric Owens 79 Nov 16, 2022
NORETURN is an esoteric programming language, based around the idea of not going back

NORETURN NORETURN is an esoteric programming language, based around the idea of not going back Concept Program coded in noreturn runs over one array,

1 Dec 15, 2021
Bad Apple printed out on the console with Python!

bad-apple Bad Apple printed out on the console with Python! Preface A word of disclaimer, while the final code is somewhat original, this project is a

CalvinLoke 186 Dec 01, 2022
Backtest framework based on DAGs

MultitaskQueue It's a simple framework based on three composed concepts: Task: A task is the smaller unit of execution or simple a node in the DAG, ev

4 Dec 09, 2021
《赛马娘》(ウマ娘: Pretty Derby)辅助 🐎🖥 基于 auto-derby 可视化操作/设置 启动器 一键包

ok-derby 《赛马娘》(ウマ娘: Pretty Derby)辅助 🐎 🖥 基于 auto-derby 可视化操作/设置 启动器 一键包 便捷,好用的 auto_derby 管理器! 功能 支持客户端 DMM (前台) 实验性 安卓 ADB 连接(后台)开发基于 1080x1920 分辨率

秋葉あんず 90 Jan 01, 2023
User management system (UMS), has the primary purpose of connecting to an Active Directory (AD)

💿 Sistema de Gerenciamento de Usuário (SGU) 📚 Sobre o projeto Sistema de gerenciamento de usuários (SGU), tem o objetivo primário de se conectar a u

Patrick Viegas 2 Feb 25, 2022
Tracing and Observability with OpenFaaS

Tracing and Observability with OpenFaaS Today we will walk through how to add OpenTracing or OpenTelemetry with Grafana's Tempo. For this walk-through

Lucas Roesler 8 Nov 17, 2022
A simple wrapper for joy library

Joy CodeGround A simple wrapper for joy library to render joy sketches in browser using vs code, (or in other words, for those who are allergic to Jup

rijfas 9 Sep 08, 2022
Nextstrain build targeted to Omicron

About This repository analyzes viral genomes using Nextstrain to understand how SARS-CoV-2, the virus that is responsible for the COVID-19 pandemic, e

Bedford Lab 9 May 25, 2022
Nick Craig-Wood's Website

Nick Craig-Wood's public website This directory tree is used to build all the different docs for Nick Craig-Wood's website. The content here is (c) Ni

Nick Craig-Wood 2 Sep 02, 2022
Script for resizing MTD partitions on a QNAP device in order to be available to upgrade from buster to bullseye

QNAP partitions resize for kirkwood devices. As explained by Marin Michlmayr, Debian bullseye support on kirkwood QNAP devices was dropped due to [mai

Arnaud Mouiche 26 Jan 05, 2023
Python module for creating the circuit simulation definitions for Elmer FEM

elmer_circuitbuilder Python module for creating the circuit simulation definitions for Elmer FEM. The circuit definitions enable easy setup of coils (

5 Oct 03, 2022
Python template for Advent of Code event

Advent of Code Python Starter A tamplate for Advent of Code write in Python. Usage The project use poetry for project manager. Clone this repository a

Leonardo Gago 6 Dec 31, 2022
Nateve transpiler developed with python.

Adam Adam is a Nateve Programming Language transpiler developed using Python. Nateve Nateve is a new general domain programming language open source i

Nateve 7 Jan 15, 2022
Stopmagic gives you the power of creating amazing Stop Motion animations faster and easier than ever before.

Stopmagic gives you the power of creating amazing Stop Motion animations faster and easier than ever before. This project is maintained by Aldrin Mathew.

Aldrin's Art Factory 67 Dec 31, 2022
Remote Worker

Remote Worker Separation of Responsibilities There are several reasons to move some processing out of the main code base for security or performance:

V2EX 69 Dec 05, 2022
Push a record and you will receive a email when that date

Push a record and you will receive a email when that date

5 Nov 28, 2022
Small Arrow Vortex clipboard processing library

Description Small Arrow Vortex clipboard processing library. Install You can install this library from PyPI with pip install av-clipboard-lib or compi

Delta Epsilon 1 Dec 18, 2021