{ "info": { "author": "Philipp von Weitershausen", "author_email": "philipp@weitershausen.de", "bugtrack_url": null, "classifiers": [], "description": "Read & write properties\n========================\n\n:Author: Philipp von Weitershausen\n:Email: philikon@philikon.de\n:License: Zope Public License, v2.1\n\nMotivation\n----------\n\nUsing method decorators and descriptors like ``property``, we can\neasily create computed attributes:\n\n >>> class JamesBrown(object):\n ... @property\n ... def feel(self):\n ... return self._feel\n\nAn attribute like this cannot be written, though. You would have to\ndo something like this:\n\n >>> class JamesBrown(object):\n ... def _getFeel(self):\n ... return self._feel\n ... def _setFeel(self, feel):\n ... self._feel = feel\n ... feel = property(_getFeel, _setFeel)\n\nThe problem with this approach is that it leaves the getter and setter\nsitting around in the class namespace. It also lacks the compact\nspelling of a decorator solution. To cope with that, some people like\nto write:\n\n >>> class JamesBrown(object):\n ... @apply\n ... def feel():\n ... def get(self):\n ... return self._feel\n ... def set(self, feel):\n ... self._feel = feel\n ... return property(get, set)\n\nThis spelling feels rather cumbersome, apart from the fact that\n``apply`` is `going to go away`_ in Python 3000.\n\n.. _going to go away: http://www.python.org/peps/pep-3000.html#id24\n\n\nGoal\n----\n\nThere should be a way to declare a read & write property and still use\nthe compact and easy decorator spelling. The read & write properties\nshould be as easy to use as the read-only property. We explicitly\ndon't want that immediately called function that really just helps us\nname the attribute and create a local scope for the getter and setter.\n\n\nRead & write property\n---------------------\n\nRead & write properties work like regular properties. You simply\ndefine a method and then apply a decorator, except that you now don't\nuse ``@property`` but ``@getproperty`` to mark the getter and\n``@setproperty`` to mark the setter:\n\n >>> from rwproperty import getproperty, setproperty\n >>> class JamesBrown(object):\n ... @getproperty\n ... def feel(self):\n ... return self._feel\n ... @setproperty\n ... def feel(self, feel):\n ... self._feel = feel\n\n >>> i = JamesBrown()\n >>> i.feel\n Traceback (most recent call last):\n ...\n AttributeError: 'JamesBrown' object has no attribute '_feel'\n\n >>> i.feel = \"good\"\n >>> i.feel\n 'good'\n\nThe order in which getters and setters are declared doesn't matter:\n\n >>> from rwproperty import getproperty, setproperty\n >>> class JamesBrown(object):\n ... @setproperty\n ... def feel(self, feel):\n ... self._feel = feel\n ... @getproperty\n ... def feel(self):\n ... return self._feel\n\n >>> i = JamesBrown()\n >>> i.feel = \"good\"\n >>> i.feel\n 'good'\n\nOf course, deleters are also possible:\n\n >>> from rwproperty import delproperty\n >>> class JamesBrown(object):\n ... @setproperty\n ... def feel(self, feel):\n ... self._feel = feel\n ... @getproperty\n ... def feel(self):\n ... return self._feel\n ... @delproperty\n ... def feel(self):\n ... del self._feel\n\n >>> i = JamesBrown()\n >>> i.feel = \"good\"\n >>> del i.feel\n >>> i.feel\n Traceback (most recent call last):\n ...\n AttributeError: 'JamesBrown' object has no attribute '_feel'\n\n\nEdge cases\n----------\n\nThere might be a case where you're using a flavour of read & write\nproperties and already have a non-property attribute of the same name\ndefined:\n\n >>> class JamesBrown(object):\n ... feel = \"good\"\n ... @getproperty\n ... def feel(self):\n ... return \"so good\"\n ...\n Traceback (most recent call last):\n ...\n TypeError: read & write properties cannot be mixed with other attributes except regular property objects.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/rwproperty", "keywords": null, "license": "ZPL", "maintainer": null, "maintainer_email": null, "name": "rwproperty", "package_url": "https://pypi.org/project/rwproperty/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/rwproperty/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/rwproperty" }, "release_url": "https://pypi.org/project/rwproperty/1.0/", "requires_dist": null, "requires_python": null, "summary": "Read & write properties", "version": "1.0" }, "last_serial": 799148, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "51ed26b228ecf44fe4b6e338ef23f3c5", "sha256": "e50f3fe67bf418de845a5cf95c1695d703d3d84984c31e46a1b301598846cfac" }, "downloads": -1, "filename": "rwproperty-1.0-py2.4.egg", "has_sig": false, "md5_digest": "51ed26b228ecf44fe4b6e338ef23f3c5", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 3946, "upload_time": "2007-03-01T02:24:47", "url": "https://files.pythonhosted.org/packages/b5/6b/76cd9560ad57172c1f331d9e9ae58c3f76078fbe35c811661870d5d94de1/rwproperty-1.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "050bdf066492b3cd82a3399f8efea6b1", "sha256": "49742642f2b5e6b0861b35a43ceda2b1aad3c5173dbd6f3e4ce1cb10037f8416" }, "downloads": -1, "filename": "rwproperty-1.0.tar.gz", "has_sig": false, "md5_digest": "050bdf066492b3cd82a3399f8efea6b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2912, "upload_time": "2007-03-01T02:24:47", "url": "https://files.pythonhosted.org/packages/71/fc/e3d922fc07db990f9aa235a2b1c690a167a9403aadc6ac30afb59e7cc0b4/rwproperty-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "51ed26b228ecf44fe4b6e338ef23f3c5", "sha256": "e50f3fe67bf418de845a5cf95c1695d703d3d84984c31e46a1b301598846cfac" }, "downloads": -1, "filename": "rwproperty-1.0-py2.4.egg", "has_sig": false, "md5_digest": "51ed26b228ecf44fe4b6e338ef23f3c5", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 3946, "upload_time": "2007-03-01T02:24:47", "url": "https://files.pythonhosted.org/packages/b5/6b/76cd9560ad57172c1f331d9e9ae58c3f76078fbe35c811661870d5d94de1/rwproperty-1.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "050bdf066492b3cd82a3399f8efea6b1", "sha256": "49742642f2b5e6b0861b35a43ceda2b1aad3c5173dbd6f3e4ce1cb10037f8416" }, "downloads": -1, "filename": "rwproperty-1.0.tar.gz", "has_sig": false, "md5_digest": "050bdf066492b3cd82a3399f8efea6b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2912, "upload_time": "2007-03-01T02:24:47", "url": "https://files.pythonhosted.org/packages/71/fc/e3d922fc07db990f9aa235a2b1c690a167a9403aadc6ac30afb59e7cc0b4/rwproperty-1.0.tar.gz" } ] }