🎰 Slotscheck
=============
.. image:: https://img.shields.io/pypi/v/slotscheck.svg?color=blue
:target: https://pypi.python.org/pypi/slotscheck
.. image:: https://img.shields.io/pypi/l/slotscheck.svg
:target: https://pypi.python.org/pypi/slotscheck
.. image:: https://img.shields.io/pypi/pyversions/slotscheck.svg
:target: https://pypi.python.org/pypi/slotscheck
.. image:: https://img.shields.io/readthedocs/slotscheck.svg
:target: http://slotscheck.readthedocs.io/
.. image:: https://github.com/ariebovenberg/slotscheck/actions/workflows/build.yml/badge.svg
:target: https://github.com/ariebovenberg/slotscheck/actions/workflows/build.yml
.. image:: https://img.shields.io/codecov/c/github/ariebovenberg/slotscheck.svg
:target: https://codecov.io/gh/ariebovenberg/slotscheck
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
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 `blog post <https://dev.arie.bovenberg.net/blog/finding-broken-slots-in-popular-python-libraries/>`_
for the origin story behind ``slotscheck``.
Quickstart
----------
Usage is quick from the command line:
.. code-block:: bash
python -m slotscheck [FILES]...
# or
slotscheck -m [MODULES]...
For example:
.. code-block:: bash
$ 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 <https://slotscheck.rtfd.io/en/latest/advanced.html#pre-commit-hook>`_
to prevent mistakes from creeping in again!
See `here <https://github.com/Instagram/LibCST/pull/615>`__ and
`here <https://github.com/dry-python/returns/pull/1233>`__ for examples.
Features
--------
- Detect broken slots inheritance
- Detect overlapping slots
- Detect duplicate slots
- `Pre-commit <https://slotscheck.rtfd.io/en/latest/advanced.html#pre-commit-hook>`_ hook
- (Optionally) enforce the use of slots
See `the documentation <https://slotscheck.rtfd.io>`_ 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 <https://github.com/ariebovenberg/slotscheck/issues/6>`_
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.
- 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 <https://github.com/ariebovenberg/slotscheck/issues/178>`_.
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 <https://github.com/ariebovenberg/slotscheck/issues/270>`_.
Installation
------------
It's available on PyPI.
.. code-block:: bash
pip install slotscheck
Raw data
{
"_id": null,
"home_page": "https://github.com/ariebovenberg/slotscheck",
"name": "slotscheck",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8.1",
"maintainer_email": null,
"keywords": null,
"author": "Arie Bovenberg",
"author_email": "a.c.bovenberg@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4b/57/6fcb8df11e7c76eb87b23bfa931408e47f051c6161749c531b4060a45516/slotscheck-0.19.1.tar.gz",
"platform": null,
"description": "\ud83c\udfb0 Slotscheck\n=============\n\n.. image:: https://img.shields.io/pypi/v/slotscheck.svg?color=blue\n :target: https://pypi.python.org/pypi/slotscheck\n\n.. image:: https://img.shields.io/pypi/l/slotscheck.svg\n :target: https://pypi.python.org/pypi/slotscheck\n\n.. image:: https://img.shields.io/pypi/pyversions/slotscheck.svg\n :target: https://pypi.python.org/pypi/slotscheck\n\n.. image:: https://img.shields.io/readthedocs/slotscheck.svg\n :target: http://slotscheck.readthedocs.io/\n\n.. image:: https://github.com/ariebovenberg/slotscheck/actions/workflows/build.yml/badge.svg\n :target: https://github.com/ariebovenberg/slotscheck/actions/workflows/build.yml\n\n.. image:: https://img.shields.io/codecov/c/github/ariebovenberg/slotscheck.svg\n :target: https://codecov.io/gh/ariebovenberg/slotscheck\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/psf/black\n\nAdding ``__slots__`` to a class in Python is a great way to improve performance.\nBut to work properly, all base classes need to implement it \u2014 without overlap!\nIt's easy to get wrong, and what's worse: there is nothing warning you that you messed up.\n\n\u2728 *Until now!* \u2728\n\n``slotscheck`` helps you validate your slots are working properly.\nYou can even use it to enforce the use of slots across (parts of) your codebase.\n\nSee my `blog post <https://dev.arie.bovenberg.net/blog/finding-broken-slots-in-popular-python-libraries/>`_\nfor the origin story behind ``slotscheck``.\n\nQuickstart\n----------\n\nUsage is quick from the command line:\n\n.. code-block:: bash\n\n python -m slotscheck [FILES]...\n # or\n slotscheck -m [MODULES]...\n\nFor example:\n\n.. code-block:: bash\n\n $ slotscheck -m sanic\n ERROR: 'sanic.app:Sanic' defines overlapping slots.\n ERROR: 'sanic.response:HTTPResponse' has slots but superclass does not.\n Oh no, found some problems!\n Scanned 72 module(s), 111 class(es).\n\nNow get to fixing \u2014\nand add ``slotscheck`` to your CI pipeline or\n`pre-commit <https://slotscheck.rtfd.io/en/latest/advanced.html#pre-commit-hook>`_\nto prevent mistakes from creeping in again!\nSee `here <https://github.com/Instagram/LibCST/pull/615>`__ and\n`here <https://github.com/dry-python/returns/pull/1233>`__ for examples.\n\nFeatures\n--------\n\n- Detect broken slots inheritance\n- Detect overlapping slots\n- Detect duplicate slots\n- `Pre-commit <https://slotscheck.rtfd.io/en/latest/advanced.html#pre-commit-hook>`_ hook\n- (Optionally) enforce the use of slots\n\nSee `the documentation <https://slotscheck.rtfd.io>`_ for more details\nand configuration options.\n\nWhy not a flake8 plugin?\n------------------------\n\nFlake8 plugins need to work without running the code.\nMany libraries use conditional imports, star imports, re-exports,\nand define slots with decorators or metaclasses.\nThis all but requires running the code to determine the slots and class tree.\n\nThere's `an issue <https://github.com/ariebovenberg/slotscheck/issues/6>`_\nto discuss the matter.\n\nNotes\n-----\n\n- ``slotscheck`` will try to import all submodules of the given package.\n If there are scripts without ``if __name__ == \"__main__\":`` blocks,\n they may be executed.\n- Even in the case that slots are not inherited properly,\n there may still be an advantage to using them\n (i.e. attribute access speed and *some* memory savings).\n However, in most cases this is unintentional.\n ``slotscheck`` allows you to ignore specific cases.\n- Because ``slotscheck`` imports your code in arbitrary order,\n it can\u2014in rare cases\u2014result in confusing and randomly-occurring import errors\n in third-party libraries.\n In such a case, it is recommended to omit modules such as your tests\n and mypy plugins from the slotscheck run.\n See `here <https://github.com/ariebovenberg/slotscheck/issues/178>`_.\n Alternatively, you can use ``PYTHONHASHSEED=<any value>`` to make the import order deterministic.\n A solution to this problem is being worked on in `this issue <https://github.com/ariebovenberg/slotscheck/issues/270>`_.\n\nInstallation\n------------\n\nIt's available on PyPI.\n\n.. code-block:: bash\n\n pip install slotscheck\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Ensure your __slots__ are working properly.",
"version": "0.19.1",
"project_urls": {
"Homepage": "https://github.com/ariebovenberg/slotscheck",
"Repository": "https://github.com/ariebovenberg/slotscheck"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "da32bd569256267f80b76b87d21a09795741a175778b954bee1d7b1a89852b6f",
"md5": "f4143bb351bedf7f5f928f4ec0738711",
"sha256": "bff9926f8d6408ea21b6c6bbaa4389cea1682962e73ee4f30084b6d2b89260ee"
},
"downloads": -1,
"filename": "slotscheck-0.19.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f4143bb351bedf7f5f928f4ec0738711",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.1",
"size": 16995,
"upload_time": "2024-10-19T13:30:51",
"upload_time_iso_8601": "2024-10-19T13:30:51.230146Z",
"url": "https://files.pythonhosted.org/packages/da/32/bd569256267f80b76b87d21a09795741a175778b954bee1d7b1a89852b6f/slotscheck-0.19.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4b576fcb8df11e7c76eb87b23bfa931408e47f051c6161749c531b4060a45516",
"md5": "ea4e1dfd3ab0d957a6d2ef8578d3fe5a",
"sha256": "6146b7747f8db335a00a66b782f86011b74b995f61746dc5b36a9e77d5326013"
},
"downloads": -1,
"filename": "slotscheck-0.19.1.tar.gz",
"has_sig": false,
"md5_digest": "ea4e1dfd3ab0d957a6d2ef8578d3fe5a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.1",
"size": 16050,
"upload_time": "2024-10-19T13:30:53",
"upload_time_iso_8601": "2024-10-19T13:30:53.369736Z",
"url": "https://files.pythonhosted.org/packages/4b/57/6fcb8df11e7c76eb87b23bfa931408e47f051c6161749c531b4060a45516/slotscheck-0.19.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-19 13:30:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ariebovenberg",
"github_project": "slotscheck",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "slotscheck"
}