{ "info": { "author": "Adrian Stachlewski", "author_email": "starhel.github@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# dataslots\n[![Build Status](https://travis-ci.org/starhel/dataslots.svg?branch=master)](https://travis-ci.org/starhel/dataslots)\n[![codecov](https://codecov.io/gh/starhel/dataslots/branch/master/graph/badge.svg)](https://codecov.io/gh/starhel/dataslots)\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/dataslots.svg)](https://pypi.org/project/dataslots/)\n[![PyPI - Status](https://img.shields.io/pypi/status/dataslots.svg)](https://pypi.org/project/dataslots/)\n![license](https://img.shields.io/github/license/starhel/dataslots.svg)\n\n## Decorator for adding __slots__\nPython3.7 provides dataclasses module for faster class creation ([PEP 557](https://www.python.org/dev/peps/pep-0557/)).\nUnfortunately there's no support for \\_\\_slots__. If you want to create more memory efficient instances, you need to \ndo it by yourself or use dataslots.with_slots decorator. \n\n## Usage\n#### Simple example\n```python\n@with_slots\n@dataclass\nclass Point2D:\n x: int\n y: int\n```\n#### Inheritance\nAs described in docs, in derived class \\_\\_dict__ is created, because base class does not have \\_\\_slots__. \nSlots are created from all defined properties (returned by dataclasses.fields() function).\n```python\n@dataclass\nclass Base:\n a: int\n\n\n@with_slots\n@dataclass\nclass Derived(Base):\n c: int\n d: int\n```\n\n#### Dynamic assignment of new variables\n```python\n@with_slots(add_dict=True)\n@dataclass\nclass Point2D:\n x: int\n y: int\n \npoint = Point2D(10, 20)\npoint.length = math.sqrt(point.x ** 2 + point.y ** 2)\n```\n\n#### Weakref\n```python\n@with_slots(add_weakref=True)\n@dataclass\nclass Point2D:\n x: int\n y: int\n \npoint = Point2D(10, 20)\nr = weakref.ref(point)\n```\n\n#### Read-only class variables\nWith \\_\\_slots__ it's possible to define read-only class variables. When using dataclasses you cannot provide type \nfor attribute or use typing.ClassVar to declare one. \n```python\n@with_slots\n@dataclass\nclass A:\n x = 5\n y: ClassVar[set] = set()\n```\n\n## More about \\_\\_slots__\n* https://docs.python.org/3/reference/datamodel.html#slots\n* https://github.com/ericvsmith/dataclasses/issues/28\n\n[dataclasses_issue]: https://github.com/ericvsmith/dataclasses/issues/28", "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/starhel/dataslots", "keywords": "dataslots,slots,dataclasses", "license": "", "maintainer": "", "maintainer_email": "", "name": "dataslots", "package_url": "https://pypi.org/project/dataslots/", "platform": "", "project_url": "https://pypi.org/project/dataslots/", "project_urls": { "Homepage": "https://github.com/starhel/dataslots" }, "release_url": "https://pypi.org/project/dataslots/1.0.1/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Decorator to add __slots__ in dataclasses", "version": "1.0.1" }, "last_serial": 4159476, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "d6f564656a2f34181a325c50dbfc46bc", "sha256": "c4478589fb1c67afaf5f6e59d6d45a6e17ca08a082a73e8ac1387f1f393fbde1" }, "downloads": -1, "filename": "dataslots-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d6f564656a2f34181a325c50dbfc46bc", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 2569, "upload_time": "2018-03-20T21:37:35", "url": "https://files.pythonhosted.org/packages/d4/82/c19d83aaa1b2ae1b19b924343bd8b3a2763930b13c436d923a33abc4f0f0/dataslots-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "241bb8a96644fa32a116888dc4e1e3df", "sha256": "e2fb733f9a65a48b1d6edd17dbb9a77ee959362dfaeb7d09a14cf02378a40021" }, "downloads": -1, "filename": "dataslots-1.0.1.tar.gz", "has_sig": false, "md5_digest": "241bb8a96644fa32a116888dc4e1e3df", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 2699, "upload_time": "2018-08-11T11:06:55", "url": "https://files.pythonhosted.org/packages/f4/43/058405488f368d9651fa07474067fb438063f9730b6385b8504edc961d64/dataslots-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "241bb8a96644fa32a116888dc4e1e3df", "sha256": "e2fb733f9a65a48b1d6edd17dbb9a77ee959362dfaeb7d09a14cf02378a40021" }, "downloads": -1, "filename": "dataslots-1.0.1.tar.gz", "has_sig": false, "md5_digest": "241bb8a96644fa32a116888dc4e1e3df", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 2699, "upload_time": "2018-08-11T11:06:55", "url": "https://files.pythonhosted.org/packages/f4/43/058405488f368d9651fa07474067fb438063f9730b6385b8504edc961d64/dataslots-1.0.1.tar.gz" } ] }