{ "info": { "author": "Philipp von Weitershausen", "author_email": "philipp@weitershausen.de", "bugtrack_url": null, "classifiers": [], "description": "Class 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\nClass properties\n----------------\n\nClass properties let you define properties via the ``class``\nstatement. You define a dynamic property as if you were implementing\na class. This works like this:\n\n >>> from classproperty import classproperty\n >>> class JamesBrown(object):\n ... class feel(classproperty):\n ... def __get__(self):\n ... return self._feel\n ... def __set__(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\nOf course, deleters are also possible:\n\n >>> class JamesBrown(object):\n ... class feel(classproperty):\n ... def __get__(self):\n ... return self._feel\n ... def __set__(self, feel):\n ... self._feel = feel\n ... def __delete__(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'", "description_content_type": null, "docs_url": null, "download_url": "http://codespeak.net/svn/user/philikon/classproperty#egg=classproperty-dev", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.z3lab.org/sections/blogs/philipp-weitershausen/2006_05_29_pycon-06-lightning-talk", "keywords": null, "license": "ZPL", "maintainer": null, "maintainer_email": null, "name": "classproperty", "package_url": "https://pypi.org/project/classproperty/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/classproperty/", "project_urls": { "Download": "http://codespeak.net/svn/user/philikon/classproperty#egg=classproperty-dev", "Homepage": "http://www.z3lab.org/sections/blogs/philipp-weitershausen/2006_05_29_pycon-06-lightning-talk" }, "release_url": "https://pypi.org/project/classproperty/1.0/", "requires_dist": null, "requires_python": null, "summary": "Class properties", "version": "1.0" }, "last_serial": 802822, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "8335f5adfd32825066b34c675fc36ff6", "sha256": "65d6faa6c6af6882c3f794ccef46f303ddcb22782a6a303c0ddda0cf2ca55e35" }, "downloads": -1, "filename": "classproperty-1.0-py2.4.egg", "has_sig": false, "md5_digest": "8335f5adfd32825066b34c675fc36ff6", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 2786, "upload_time": "2007-04-10T17:40:23", "url": "https://files.pythonhosted.org/packages/39/16/5766696472cab336f44ce826384e0a183e0018e0c37079b11a23df93cf04/classproperty-1.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "5abd0527fcf8884b7d07203a0967a433", "sha256": "c2caea61ed431ade216aed9f5253225a23b383252cc954fb254ea9487cea7056" }, "downloads": -1, "filename": "classproperty-1.0.tar.gz", "has_sig": false, "md5_digest": "5abd0527fcf8884b7d07203a0967a433", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2313, "upload_time": "2007-04-10T17:40:21", "url": "https://files.pythonhosted.org/packages/26/01/d0590085d6dcf0182a6ad43b89826726f5d01b6679745c468c78c6b74197/classproperty-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8335f5adfd32825066b34c675fc36ff6", "sha256": "65d6faa6c6af6882c3f794ccef46f303ddcb22782a6a303c0ddda0cf2ca55e35" }, "downloads": -1, "filename": "classproperty-1.0-py2.4.egg", "has_sig": false, "md5_digest": "8335f5adfd32825066b34c675fc36ff6", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 2786, "upload_time": "2007-04-10T17:40:23", "url": "https://files.pythonhosted.org/packages/39/16/5766696472cab336f44ce826384e0a183e0018e0c37079b11a23df93cf04/classproperty-1.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "5abd0527fcf8884b7d07203a0967a433", "sha256": "c2caea61ed431ade216aed9f5253225a23b383252cc954fb254ea9487cea7056" }, "downloads": -1, "filename": "classproperty-1.0.tar.gz", "has_sig": false, "md5_digest": "5abd0527fcf8884b7d07203a0967a433", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2313, "upload_time": "2007-04-10T17:40:21", "url": "https://files.pythonhosted.org/packages/26/01/d0590085d6dcf0182a6ad43b89826726f5d01b6679745c468c78c6b74197/classproperty-1.0.tar.gz" } ] }