Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install pysynthetic

How to install pysynthetic

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install pysynthetic
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)
0.4.10 Available View build log
0.4.10 Available View build log
 
Author
License
MIT
Dependencies
Imports
Lastest release
version 0.4.10 on May 5th, 2013

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!

https://api.flattr.com/button/flattr-badge-large.png https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif

Installation

System Message: ERROR/3 (<string>, line 29)

Unknown directive type "code-block".

.. code-block:: shell

    pip install pysynthetic

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

System Message: ERROR/3 (<string>, line 35)

Unknown directive type "code-block".

.. code-block:: shell

    python setup.py install

Examples

Synthetic properties

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

System Message: ERROR/3 (<string>, line 47)

Unknown directive type "code-block".

.. code-block:: python

    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):

System Message: ERROR/3 (<string>, line 60)

Unknown directive type "code-block".

.. code-block:: python

    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)...

System Message: ERROR/3 (<string>, line 112)

Unknown directive type "code-block".

.. code-block:: python

    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):

System Message: ERROR/3 (<string>, line 125)

Unknown directive type "code-block".

.. code-block:: python

    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

Subscribe to package updates

Last updated May 5th, 2013

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.