pinstance 0.1.0

Creator: railscoder56

Last updated:

Add to Cart

Description:

pinstance 0.1.0

Pinstance
Simple singleton class decorator with
ability to call bounded methods with 0 overhead.
Decorated class can inherit other classes and can be inherited.
Decorated class can not be collected till the end of a programm
Usage
Decorate a class:
@instanceclass
class MyClass:
def __init__(self, val):
self.class_var = val

Now you can instanciate it
inst = MyClass(777)
inst.class_var ## 777

and access the instance anywhere via get_instance() class method:
MyClass.get_instance().class_var ## 777
MyClass.get_instance().some_var = 555
MyClass.get_instance().class_var ## 555

Furthermore, to simplify calling methods via instance reference one can decorate desiered @instanceclass methods:
@instancemethod
def my_function(self, param):
print(f'{self.class_var} | {param}')

and call them like static methods with 0 overhead:
MyClass.my_function('example') ## 555 | example

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.