autoslot
Project description
autoslot
Automatic “__slots__”.
Demo
from autoslot import Slots
class Compact(Slots):
def __init__(self, a, b):
self.x = a
self.y = b
This produces _exactly_ the same class as if you had done:
class Compact:
__slots__ = {'x', 'y'}
def __init__(self, a, b):
self.x = a
self.y = b
The benefit of using the metaclass version is that you can modify the code inside the __init__() method to add more attributes, and those changes will automatically be reflected in the __slots__ definition.
How does it work?
See for yourself–the code is embarrassingly small!
In words: the metaclass finds the __init__() method, if present, and accesses its bytecode. It looks for all assignments to attributes of self, and considers those to be desired __slots__ entries. Then the metaclass injects __slots__ into the namespace of the class definition and thereafter allows class creation to proceed as normal.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file autoslot-2017.10.3.tar.gz
.
File metadata
- Download URL: autoslot-2017.10.3.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 208253af5168297c85edb60a8c32dcc70cd6e66d36a2bd92d5f4be98c401020a |
|
MD5 | ddddfb002277f55f246185e269fdc4ec |
|
BLAKE2b-256 | 6cf9a5aaeaa45fab80bcc02e7d76dcfdaf77e95b8824881d4f2dd1734e4cd966 |
File details
Details for the file autoslot-2017.10.3-py3-none-any.whl
.
File metadata
- Download URL: autoslot-2017.10.3-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18d90dd13a93d4c946ad33ced1e339f04d9089891bb637621f66d46b6d575e7 |
|
MD5 | 7d4761516faa32bf4ee00ed6c4ad0133 |
|
BLAKE2b-256 | 84080684ad16ef5ba2fd92f269b44651ed69a0ec43c1630c09034f9450381f73 |