This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

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!

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)

from synthetic import synthesize_constructor, synthesize_property

@synthesize_property('a', contract = int)
@synthesize_property('b', contract = list)
@synthesize_property('c', default = "", contract = str, read_only = True)
@synthesize_constructor()
class ShortAndClean(object):
    pass

… replaces this (43 lines):

from contracts import contract

class ThisHurtsMyKeyboard(object):

    @contract
    def __init__(self, a, b, c = ""):
        """
    :type a: int
    :type b: list
    :type c: str
"""
        self._a = a
        self._b = b
        self._c = c

    @property
    def a(self):
        return self._a

    @a.setter
    @contract
    def a(self, value):
        """
    :type value: int
"""
        self._a = value

    @property
    def b(self):
        return self._b

    @b.setter
    @contract
    def b(self, value):
        """
    :type value: list
"""
        self._b = value

    @property
    def c(self):
        return self._c

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)

from synthetic import synthesize_constructor, synthesize_member

@synthesize_member('a', contract = int)
@synthesize_member('b', contract = list)
@synthesize_member('c', default = "", contract = str, read_only = True)
@synthesize_constructor()
class ShortAndClean(object):
    pass

…will replace this (37 lines):

from contracts import contract

class ThisHurtsMyKeyboard(object):

    @contract
    def __init__(self, a, b, c = ""):
        """
    :type a: int
    :type b: list
    :type c: str
"""
        self._a = a
        self._b = b
        self._c = c

    def a(self):
        return self._a

    @contract
    def set_a(self, value):
        """
    :type value: int
"""
        self._a = value

    def b(self):
        return self._b

    @contract
    def set_b(self, value):
        """
    :type value: list
"""
        self._b = value

    def c(self):
        return self._c
Release History

Release History

0.5.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.14

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.13

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.12

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.11

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.10

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.9

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pysynthetic-0.5.0.tar.gz (150.3 kB) Copy SHA256 Checksum SHA256 Source Nov 2, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting