Automatically log all new subclasses of a specified base class.
Project description
Motivation
This library implements a simple clas decorator that you can apply to a base class. This decorator then hooks into the way the decorated class is subclassed, adding all new subclasses to a dictionary whose keys are class names and values are the classes themselves.
The motivation for this project was to autogenerate deep learning models from pure JSON files, thus ensuring reproducibility of the results. I do, however, think that it is ideal for any kind of codebase where we want to generate safe code from configuration files.
Installation instructions
The subclass register can be installed with pip:
pip install subclass-register
by cloning this repo and running setup.py
git clone https:\\github.com\yngvem\subclass-register
cd subclass-register
python setup.py
or by simply downloading the src\subclass_register\subclass_register.py file and the LISENCE file into your project.
Example
Here is a basic example of how to use the subclass register.
from subclass_register import SubclassRegister
register = SubclassRegister('car')
@register.link_base
class BaseCar:
pass
class SUV(BaseCar):
def __init__(self, horse_powers):
self.horse_powers = horse_powers
suv = register['SUV'](horse_powers = 50)
You can read more examples at the documentation page.
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
Hashes for subclass_register-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1515d0275ebb2c4c52956d2bc2519afe80267e87248cf20ba2ff7565fc5d081a |
|
MD5 | 94fea33704847d2b27933b771fd3eb98 |
|
BLAKE2b-256 | 5dff823416d8410809918286ae0e728d73b7348800e740b9acfdaf7a10b03d00 |