{ "info": { "author": "book987", "author_email": "book78987book@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# partial readonly\n\n`partial_readonly` provide a decorator for conveniently making some fields read-only in dataclass. No dependencies other than the Python Standard Library.\n\n\n\n\n## Usage\n\n\n### Quick Start\n\nWith `partail_readonly`, we can easily make some of the fields in `dataclass` read-only by creating property related to them. __(Notice: We still can't make the origin field read-only, cause it still need to be set while calling `__init__`)__\n\nFor example, the following code\n```python\nfrom dataclasses import dataclass\n\n@dataclass\nclass Data:\n id: int = 0\n name: str = ''\n\n @property\n def full_name(self): return self.name\n```\ncan be written like this by using `partial_readonly`\n```python\nfrom dataclasses import dataclass\n\n@dataclass\nclass Data:\n id: int = 0\n _name: 'str alias=full_name' = ''\n```\n\n### Details\n\n1. Mark a field read-only by adding an underline prefix\n - `_id: int` means `id` is read-only\n2. By default, the relative property named like field without underline prefix\n - `_id: int` will generate a property named `id`\n3. Use string annotation and add `alias=alias_you_want` at the end, and you'll have a property named `alias_you_want`\n - `_id: 'int alias=security_id` will generate a property named `security_id`\n\n\n## Installation\n\nTo install `partial_readonly`, simply use `pip`:\n\n```pip install partial_readonly```\n\nOr use `easy_install`:\n\n```easy_install partial_readonly```\n\n\n## Deep down\n\n1. Making property read-only by set a getter[ and ban a setter]\n2. Using AST to build a getter for new property\n3. The idea about abusing annotation comes from [zmitchell/annotation-abuse](zmitchell/annotation-abuse)\n\n\n## Why partial_readonly\n\nLastest python offer us dataclass for creating some class in convenient way.\n\nBut it's not convenient when we want not all the fields be readonly.\n\n\n## Requirements\n\n- Python >= 3.7\n\n\n## Postscript\n\nI built this for practicing AST and publish.\n\nI think it work fine.\n\nThere are some more easily implementation.\n\nIf you sharing some idea about this feature I'll be greatful!\n\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2018 book987\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/book987/partial_readonly", "keywords": "dataclass readonly", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "partial-readonly", "package_url": "https://pypi.org/project/partial-readonly/", "platform": "", "project_url": "https://pypi.org/project/partial-readonly/", "project_urls": { "Homepage": "https://github.com/book987/partial_readonly" }, "release_url": "https://pypi.org/project/partial-readonly/0.0.3/", "requires_dist": null, "requires_python": ">=3.7", "summary": "make some of the dataclass fields read-only", "version": "0.0.3" }, "last_serial": 4235612, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "6310a4b61efd608860d24a11c3eb42f8", "sha256": "11efb1ff3700c67d3fb9585a48c73fdfd9a7e17e755ab96e5cabd776596f93c8" }, "downloads": -1, "filename": "partial_readonly-0.0.2.tar.gz", "has_sig": false, "md5_digest": "6310a4b61efd608860d24a11c3eb42f8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 2825, "upload_time": "2018-09-03T21:02:42", "url": "https://files.pythonhosted.org/packages/38/59/f603aead6460ec54ae2037b2b0adf19d596aad9557bbd863c97f867b8e10/partial_readonly-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "8082e9696a9275c57a8ba95f9b69b9c2", "sha256": "17ac4e5ca7cd6faa81640f47b38dc01dcb796013d7e421d06fa6d8481de9e05e" }, "downloads": -1, "filename": "partial_readonly-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "8082e9696a9275c57a8ba95f9b69b9c2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 4159, "upload_time": "2018-09-03T21:29:48", "url": "https://files.pythonhosted.org/packages/51/03/13a40b713c5fd6bdb57944f30bb5dc51488516e991f84714e1f4a7af2ace/partial_readonly-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3b6bf560a2cf7a7f48ce7405edc8d17b", "sha256": "97a4ab43769288d549a05a74069fc4f2c3c95d3b1183d13b12167cd8fc756c2a" }, "downloads": -1, "filename": "partial_readonly-0.0.3.tar.gz", "has_sig": false, "md5_digest": "3b6bf560a2cf7a7f48ce7405edc8d17b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 3904, "upload_time": "2018-09-03T21:29:49", "url": "https://files.pythonhosted.org/packages/65/40/029a015974895b2e028616afdccf509fa102c8c7eddd264a46e0e32ea8b6/partial_readonly-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8082e9696a9275c57a8ba95f9b69b9c2", "sha256": "17ac4e5ca7cd6faa81640f47b38dc01dcb796013d7e421d06fa6d8481de9e05e" }, "downloads": -1, "filename": "partial_readonly-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "8082e9696a9275c57a8ba95f9b69b9c2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 4159, "upload_time": "2018-09-03T21:29:48", "url": "https://files.pythonhosted.org/packages/51/03/13a40b713c5fd6bdb57944f30bb5dc51488516e991f84714e1f4a7af2ace/partial_readonly-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3b6bf560a2cf7a7f48ce7405edc8d17b", "sha256": "97a4ab43769288d549a05a74069fc4f2c3c95d3b1183d13b12167cd8fc756c2a" }, "downloads": -1, "filename": "partial_readonly-0.0.3.tar.gz", "has_sig": false, "md5_digest": "3b6bf560a2cf7a7f48ce7405edc8d17b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 3904, "upload_time": "2018-09-03T21:29:49", "url": "https://files.pythonhosted.org/packages/65/40/029a015974895b2e028616afdccf509fa102c8c7eddd264a46e0e32ea8b6/partial_readonly-0.0.3.tar.gz" } ] }