{ "info": { "author": "Kale Kundert", "author_email": "kale@thekunderts.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 3.3", "Topic :: Software Development :: Libraries" ], "description": "``autoprop`` --- Infer properties from accessor methods\n=======================================================\n.. image:: https://img.shields.io/pypi/v/autoprop.svg\n :target: https://pypi.python.org/pypi/autoprop\n\n.. image:: https://img.shields.io/pypi/pyversions/autoprop.svg\n :target: https://pypi.python.org/pypi/autoprop\n\n.. image:: https://img.shields.io/travis/kalekundert/autoprop.svg\n :target: https://travis-ci.org/kalekundert/autoprop\n\n.. image:: https://img.shields.io/coveralls/kalekundert/autoprop.svg\n :target: https://coveralls.io/github/kalekundert/autoprop?branch=master\n\nProperties are a feature in python that allow accessor functions (i.e. getters \nand setters) to masquerade as regular attributes. This makes it possible to \nprovide transparent APIs for classes that need to cache results, lazily load \ndata, maintain invariants, or react in any other way to attribute access.\n\nUnfortunately, making a property requires an annoying amount of boilerplate \ncode. There are a few ways to do it, but the most common and most succinct \nrequires you to decorate two functions (with two different decorators) and to \ntype the name of the attribute three times::\n\n class RegularProperty:\n \n @property\n def attr(self):\n return self._attr\n\n @attr.setter\n def attr(self, new_value):\n self._attr = new_value\n\nThe ``autoprop`` module simplifies this process by searching your class for \naccessor methods and adding properties corresponding to any such methods it \nfinds. For example, the code below defines the same property as the code \nabove::\n\n @autoprop\n class AutoProperty:\n \n def get_attr(self):\n return self._attr\n\n def set_attr(self, new_value):\n self._attr = new_value\n\nInstallation\n------------\n``autoprop`` is available on PyPI, so you can install it using ``pip``::\n\n pip install autoprop\n\nUsage\n-----\nTo use ``autoprop``, import the ``autoprop`` module and use it directly as a \nclass decorator::\n\n import autoprop\n\n @autoprop\n class Vector2D:\n \n def __init__(self, x, y):\n self._x = x\n self._y = y\n\n def get_x(self):\n return self._x\n\n def set_x(self, x):\n self._x = x\n\n def get_y(self):\n return self._y\n\n def set_y(self, y):\n self._y = y\n\nThe decorator searches your class for methods beginning with ``get_``, \n``set_``, or ``del_`` and uses them to create properties. The names of the \nproperties are taken from whatever comes after the underscore. For example, \nthe method ``get_x`` would be used to make a property called ``x``. Any \ncombination of getter, setter, and deleter methods is allowed for each \nproperty.\n\nBesides having the right prefix, there are two other criteria methods must meet \nin order to be made into properties. The first is that they must take the \nright number of required arguments. Getters and deleters can't have any \nrequired arguments (other than self). Setters must have exactly one required \nargument (other than self), which is the value to set. Default, variable, and \nkeyword arguments are all ok; only the number of required arguments matters.\n\nAny methods that have the right name but the wrong arguments are silently \nignored. This can be nice for getters that require, for example, an index. \nEven though such a getter can't be made into a property, ``autoprop`` allows it \nto follow the same naming conventions as any getters that can be::\n\n @autoprop\n class Vector2D:\n \n ...\n\n def get_coord(self, i):\n if i == 0: return self._x\n if i == 1: return self._y\n\n def set_coord(self, i, new_coord):\n if i == 0: self.x = new_coord\n if i == 1: self.y = new_coord\n\nIn this way, users of your class can always expect to find accessors named \n``get_*`` and ``set_*``, and properties corresponding to those accessors for \nbasic attributes that don't need any extra information.\n\nThe second criterion is that the property must have a name which is not already \nin use. This guarantees that nothing you explicitly add to your class will be \noverwritten, and it gives you the ability to customize how certain properties \nare defined if you'd so like. Note that this criterion does not apply to \nproperties that ``autoprop`` itself created. This really just means that if \nyou overwrite some accessors defined in a superclass, you'll get new properties \nthat refer to the overridden accessors and not be left with stale references to \nthe superclass accessors.\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kalekundert/autoprop", "keywords": "property", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "autoprop", "package_url": "https://pypi.org/project/autoprop/", "platform": "", "project_url": "https://pypi.org/project/autoprop/", "project_urls": { "Homepage": "https://github.com/kalekundert/autoprop" }, "release_url": "https://pypi.org/project/autoprop/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "", "version": "0.0.3" }, "last_serial": 2620144, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "47fd7cd486802c68ec02791a2d52b5b2", "sha256": "adf4801988949027404b9da05dc5346dc8d735b7e8f4877f9b2d23004b50138d" }, "downloads": -1, "filename": "autoprop-0.0.0.tar.gz", "has_sig": false, "md5_digest": "47fd7cd486802c68ec02791a2d52b5b2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11517, "upload_time": "2016-12-29T18:56:12", "url": "https://files.pythonhosted.org/packages/67/a5/9ce9ff16011645f6ab09216ef3c6e64c8203052f34bab867cf95f2f172f3/autoprop-0.0.0.tar.gz" } ], "0.0.1": [ { "comment_text": "", "digests": { "md5": "7561fab4cb855c17ce9d3d38480fe22b", "sha256": "38536dfafb55ff8172dfeee242cc2a071a2d7916904c38b3cdf9483132b3a9ac" }, "downloads": -1, "filename": "autoprop-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7561fab4cb855c17ce9d3d38480fe22b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11925, "upload_time": "2016-12-29T21:09:18", "url": "https://files.pythonhosted.org/packages/5c/4e/b32157c5bc1cfe7428f3368b2a70bf50541f01f49a838c5251c21f5e12bb/autoprop-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "2694dcccc21369829005142be1d54cc1", "sha256": "bc6388ee6d00ea6188ca91617a07d967fd48e7c1e677abe7f1fc2b26f2ae223d" }, "downloads": -1, "filename": "autoprop-0.0.2.tar.gz", "has_sig": false, "md5_digest": "2694dcccc21369829005142be1d54cc1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12397, "upload_time": "2017-01-02T16:24:53", "url": "https://files.pythonhosted.org/packages/3c/7f/5deb942922bd023c2eabb14d112b87c08b9f5d6913ad924f1e930d3f46ef/autoprop-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "8447cc58232ca122d866c8784fac391e", "sha256": "ab3990546a3ddea4ecae63a9378779d679ac291bd0d2be7fcf99f64b9eb60dc1" }, "downloads": -1, "filename": "autoprop-0.0.3.tar.gz", "has_sig": false, "md5_digest": "8447cc58232ca122d866c8784fac391e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10899, "upload_time": "2017-02-05T07:21:55", "url": "https://files.pythonhosted.org/packages/12/10/c9770bfc1bdfd8a001bd3677b9a80c3603f1b3236dc862e4b7c7ca620945/autoprop-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8447cc58232ca122d866c8784fac391e", "sha256": "ab3990546a3ddea4ecae63a9378779d679ac291bd0d2be7fcf99f64b9eb60dc1" }, "downloads": -1, "filename": "autoprop-0.0.3.tar.gz", "has_sig": false, "md5_digest": "8447cc58232ca122d866c8784fac391e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10899, "upload_time": "2017-02-05T07:21:55", "url": "https://files.pythonhosted.org/packages/12/10/c9770bfc1bdfd8a001bd3677b9a80c3603f1b3236dc862e4b7c7ca620945/autoprop-0.0.3.tar.gz" } ] }