{ "info": { "author": "Oz Tiram", "author_email": "oz.tiram@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Python Software Foundation License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "Python Read Only Property\n=========================\n\nBackground:\n-----------\n\n > Generally, Python programs should be written with the assumption that\n > all users are consenting adults, and thus are responsible for using things\n > correctly themsel0aves.\n\n[Silas Ray][1] in Stackoverflow. Thus, generally speaking, Python doesn't hide\nmuch. There is no notion of `private` vs. `public` in Python, hence everything\nis writable.\n\nBut what if you or users of your code forget?\nWhat if you really can't assume everyone is ?\n\nDo we give up on having read only properties in Python?\n\nShort introduction:\n-------------------\nThis module allows you to make class attribute read only, with needing to\nuse `@property` or `__getattr__`.\n\nWhy not use `@property`?\n\nBecause it's verbose, and you need to create a function which returns\nsomething.\n\n```\n class MyClass:\n\n @property\n def a(self):\n return 1\n\n```\nThe above can be shortened:\n\n```\n@read_only_properties('a')\nclass MyClass(object):\n def __init__(self, a, b, c):\n self.readonly = a\n```\nOnce assigned in the constructor, you can't change it.\n\nUsage:\n------\n\nThis package installs a single Python module `rop.py`, containing a single\ndecorator `read_only_properties`. To use it, simply import the decorator and\ndecorate your classes.\n\n```\nfrom rop import read_only_properties\n\n@read_only_properties('b')\nclass Foo:\n def __init__(self, a, b):\n self.a\n self.b\n```\n\n\nMoving from @property:\n----------------------\nIf you have a class with many attributes that you want to\nrefactor to properties:\n\n```\nclass AClassWithManyAttributes:\n def __init__(a, b, c, d, e ...)\n self.a = a\n self.b = b\n self.c = c\n``` ....\n\nThe above class would be very verbose (an IDE will save you a lot of\ntyping, but it won't make the code shorter:\n\n```\nclass AClassWithManyAttributes:\n '''refactored to properties'''\n def __init__(a, b, c, d, e ...)\n self._a = a\n self._b = b\n self._c = c\n @property\n def a(self):\n return self._a\n @property\n def b(self):\n return self._b\n @property\n def b(self):\n return self._c\n # you get this ... it's long\n\n```\n\nNow imagine you can simply do that:\n\n```\n@read_only_properties('a', 'b', 'c')\nclass AClassWithManyAttributes:\n def __init__(a, b, c, d, e)\n self.a = a\n self.b = b\n self.c = c\n self.d = d\n self.e = e\n```\n\nThis makes the attributes `a, b, c` read only, trying to re-assign a value\nto any of them will raise an exception, other class attribute stay unaffected.\n\n\nThe code for this module originated from the\n[author's answer in stackoverflow][2].\n\n\n[1]: http://stackoverflow.com/a/14594174/492620\n[2]: http://stackoverflow.com/a/35906068/492620", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/oz123/read-only-properties.git", "keywords": null, "license": "Python Software Foundation Lincese", "maintainer": null, "maintainer_email": null, "name": "read-only-property", "package_url": "https://pypi.org/project/read-only-property/", "platform": "any", "project_url": "https://pypi.org/project/read-only-property/", "project_urls": { "Homepage": "https://github.com/oz123/read-only-properties.git" }, "release_url": "https://pypi.org/project/read-only-property/0.1/", "requires_dist": null, "requires_python": null, "summary": "Create class properties which can't be changed.", "version": "0.1" }, "last_serial": 2817389, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4a5700c0f479383036557e87b169225d", "sha256": "347f28042fe95cd78ab57ab5d6ab50fc74e9757b1530e8b129b046990250183d" }, "downloads": -1, "filename": "read-only-property-0.1.tar.gz", "has_sig": false, "md5_digest": "4a5700c0f479383036557e87b169225d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3355, "upload_time": "2017-04-20T16:18:51", "url": "https://files.pythonhosted.org/packages/93/0e/d202a0cb5ef4fce40e5285d7094a1b6d1bc33392d1116e938e834645d7fd/read-only-property-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4a5700c0f479383036557e87b169225d", "sha256": "347f28042fe95cd78ab57ab5d6ab50fc74e9757b1530e8b129b046990250183d" }, "downloads": -1, "filename": "read-only-property-0.1.tar.gz", "has_sig": false, "md5_digest": "4a5700c0f479383036557e87b169225d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3355, "upload_time": "2017-04-20T16:18:51", "url": "https://files.pythonhosted.org/packages/93/0e/d202a0cb5ef4fce40e5285d7094a1b6d1bc33392d1116e938e834645d7fd/read-only-property-0.1.tar.gz" } ] }