/pysynthetic

👴🏻 Easy Python class writing and type checking

Primary LanguagePythonMIT LicenseMIT

Be synthetic with PySynthetic

PySynthetic is a set of tools that aims to make writing Python classes shorter and "cleaner".

For instance, one can add properties and accessors (getters/setters) to a class with only one line of code (using respectively synthesize_property and synthesize_member decorators), thus making the code more than 5 times shorter (see examples ). One can even avoid the laborious task of members initialization by using the synthesize_constructor decorator that takes care of writing the __init__ method.

PySynthetic is also useful for applying strict type checking with no pain just by using the decorators' contract argument (see PyContracts ).

Help and ideas are appreciated! Thank you!

image

image

Resources

Installation

pip install pysynthetic

Or simply from the tarball or source code if you are not using pip.

python setup.py install

Examples

Synthetic properties

With PySynthetic, the following code (8 lines)...

... replaces this (43 lines):

Synthetic accessors

But, if you are more into accessors than properties, you can use synthesize_member decorator instead.

This way, the following code (8 lines)...

...will replace this (37 lines):