Expand Python Super Capabilities
Project description
|build| |license| |code style| |coverage| |colab-badge|
Supercharge
This package allows you to automatically run code before and after a given class method. Furthermore, this behaviour can be enforced on child classes as well.
Example
.. code-block:: py
from supercharge import Charge
class HelloWorld:
def __init__(self):
self.run_prepared = False
self.run_state = False
@Charge
def run(self):
if self.run_prepared:
print("running ...")
@run.pre
def pre_run(self):
self.run_prepared = True
@run.post
def post_run(self):
self.run_state = True
If this is behaviour is desired in subclassed runs one must use the Base
class.
.. code-block:: py
from supercharge import Charge, Base
class HelloWorld(Base):
def __init__(self):
self.run_prepared = False
self.run_state = False
@Charge
def run(self):
raise NotImplementedError
@run.pre
def pre_run(self):
self.run_prepared = True
@run.post
def post_run(self):
self.run_state = True
class Child(HelloWorld):
def run(self):
if self.run_prepared:
print("running ...")
.. badges
.. |build| image:: https://github.com/zincware/supercharge/actions/workflows/pytest.yaml/badge.svg :alt: Build tests passing :target: https://github.com/zincware/py-test/blob/readme_badges/
.. |license| image:: https://img.shields.io/badge/License-EPL-purple.svg?style=flat :alt: Project license :target: https://www.eclipse.org/legal/epl-2.0/faq.php
.. |code style| image:: https://img.shields.io/badge/code%20style-black-black :alt: Code style: black :target: https://github.com/psf/black/
.. |coverage| image:: https://coveralls.io/repos/github/zincware/supercharge/badge.svg :alt: Code coverage :target: https://coveralls.io/github/zincware/supercharge
.. |colab-badge| image:: https://colab.research.google.com/assets/colab-badge.svg :alt: Open Example in Google Colab :target: https://colab.research.google.com/github/zincware/supercharge/blob/main/examples/introduction.ipynb
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 supercharge-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1b6e48aaaf1fb99e8dec291ba235c3c336b2e2d0330de72c70b265e15c33a73 |
|
MD5 | 1f83c667c43755886dcc9c6b43f380fc |
|
BLAKE2b-256 | 1dd48d548f108ffd8262966c16224574507f47d68a13c149cf36ec5131f365c5 |