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
Import modules and files straight from URLs.

Import Python code from modules straight from the internet.

Nate 2 Jan 15, 2022
Estimate the Market Size for Electic and Plug-In Hybrid Vehicles In Africa

Estimate the Market Size for Electic and Plug-In Hybrid Vehicles In Africa The goal of this repository is to use open data repositories to answer the

Leonce Nshuti 0 Feb 21, 2022
Desenvolvendo as habilidades básicas de programação visando a construção de aplicativos por meio de bibliotecas apropriadas à Ciência de Dados.

Algoritmos e Introdução à Computação Ementa: Conceitos básicos sobre algoritmos e métodos para sua construção. Tipos de dados e variáveis. Estruturas

Dyanna Cruz 1 Jan 06, 2022
Criando um jogo de naves espaciais com Pygame. Para iniciantes em Python

Curso de Programação de Jogos com Pygame Criando um jogo de naves espaciais com Pygame. Para iniciantes em Python Pré-requisitos Antes de começar este

Flávio Codeço Coelho 33 Dec 02, 2022
Tracking stock volatility.

SP500-highlow-tracking Track stock volatility. Being a useful indicator of the stock price volatility, High-Low gap represents the price range of the

Thong Huynh 13 Sep 07, 2022
python3 scrip for case conversion of source code files writen in fixed form fortran

convert_FORTRAN_case python3 scrip for case conversion of source code files writen in fixed form fortran python3 scrip for case conversion of source c

7 Sep 20, 2022
🔵Open many google dorks in a fasted way

Dorkinho 🔵 The author is not responsible for misuse of the tool, use it in good practices like Pentest and CTF OSINT challenges. Dorkinho is a script

SidHawks 2 May 02, 2022
Files relating to polymtl university

This is a tool I developed quickly, which allows users to visualize class availability by day of the week for a given program at polymtl. The schedule

PN 3 Mar 15, 2022
PyGo custom language, New but similar language programming

New but similar language programming. Now we are capable to program in a very similar language to Python but at the same time get the efficiency of Go.

Fernando Perez 4 Nov 19, 2022
Python framework to build apps with the GASP metaphor

Gaspium Python framework to build apps with the GASP metaphor This project is part of the Pyrustic Open Ecosystem. Installation | Documentation | Late

5 Jan 01, 2023
Euler 021 Py - Euler Problem 021 solved in Python

Euler_021_Py Euler Problem 021 solved in Python Let d(n) be defined as the sum o

Ariel Tynan 1 Jan 24, 2022
GDSC UIET KUK 📍 , welcomes you all to this amazing event where you will be introduced to the world of coding 💻 .

GDSC UIET KUK 📍 , welcomes you all to this amazing event where you will be introduced to the world of coding 💻 .

Google Developer Student Club UIET KUK 9 Mar 24, 2022
Digdata presented 'BrandX' as a clothing brand that wants to know the best places to set up a 'pop up' store.

Digdata presented 'BrandX' as a clothing brand that wants to know the best places to set up a 'pop up' store. I used the dataset given to write a program that ranks these places.

Mahmoud 1 Dec 11, 2021
A simple service that allows you to run commands on the server using text

Server Text A simple flask service that allows you to run commands on the server/computer over sms. Think of it as a shell where you run commands over

MT Devs 49 Nov 09, 2021
Islam - This is a simple python script.In this script I have written all the suras of Al Quran. As a result, by using this script, you can know the number of any sura at the moment.

Introduction: If you want to know sura number of al quran by just typing the name of sura than you can use this script. Usage in termux: $ pkg install

Fazle Rabbi 1 Jan 02, 2022
Python library to natively send files to Trash (or Recycle bin) on all platforms.

Send2Trash -- Send files to trash on all platforms Send2Trash is a small package that sends files to the Trash (or Recycle Bin) natively and on all pl

Andrew Senetar 224 Jan 04, 2023
Speed up your typing by some exercises in the multi-platform(Windows/Ubuntu).

Introduction This project purpose is speed up your typing by some exercises in the multi-platform(Windows/Ubuntu). Build Environment Software Environm

lyfer233 1 Mar 24, 2022
Pixelarticons - Pixel Art Icons made simple for Flutter, powered by pixelarticons and fontify

Pixelarticons - Pixel Art Icons made simple for Flutter, powered by pixelarticons and fontify

lask 16 Dec 12, 2022
APC Power Usage is an application which shows power consuption overtime for UPS units manufactured by APC.

APC Power Usage Introduction APC Power Usage is an application which shows power consuption overtime for UPS units manufactured by APC. Screenshoots G

Stefan Kondinski 3 Oct 08, 2021