{ "info": { "author": "Peter Zaitcev / USSX Hares", "author_email": "ussx-hares@yandex.ru", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "# Typing Tools\nThis is a library for Python 3.6+ that adds some dict-like classes supporting attributes like in JavaScript' objects. \n\nThis module provides 2 classes - _DictStruct_ and _AssignmentSupportable_.\nInherit your class from it and all the featues will enable.\nThe example below for more details.\n\n### Example Usage\n\n##### DictStruct\nLet's declare a _Circle_ and a _Point_ classes:\n```code=python\nimport json\nfrom typing import List, Dict, Tuple\nfrom typing_tools import DictStruct, AssignmentSupportable\n\nclass Point(DictStruct):\n x: int\n y: int\n\nclass Circle(DictStruct):\n r: int\n c: Point\n```\n\nLet's create a Circle object.\nIt is both a dictionary and a namespace, so the `.attribute` and `['attribute']` calls are allowed.\n```code=python\n_point_dict = { 'x': 5, 'y': 18 }\n_circle_dict = { 'c': _point_dict, 'r': 6 }\np = Point(_point_dict)\no = Circle(_circle_dict)\n```\nNote that this could also work:\n`o = Circle(r=4, c=Point(x=2, y=15))`\n\nAnd, now, print it:\n```code=python\nprint(f\"Circle is: {o}\")\nprint(f\"Circle Radius is: {o.r}\")\nprint(f\"Circle Center is: {o.c}\")\nprint(f\"Circle Center X is: {o.c.x}\")\nprint(f\"Circle Center Y is: {o.c.x}\")\nprint(json.dumps(o))\n```\n\nThis will print:\n```\nCircle is: {'r': 4, 'c': {'x': 2, 'y': 15}}\nCircle Radius is: 4\nCircle Center is: {'x': 2, 'y': 15}\nCircle Center X is: 2\nCircle Center Y is: 2\n{\"r\": 4, \"c\": {\"x\": 2, \"y\": 15}}\n```\n\nIt also supports default values and methods:\n```code=python\nclass PointWithDefaults(DictStruct):\n x: int = 0\n y: int = 0\n \n def print_me(self):\n print(f\"PointWithDefaults is: {self}\")\n print(f\"PointWithDefaults X is: {self.x} and {self['x']} and {self.get('x')}\")\n print(f\"PointWithDefaults Y is: {self.y} and {self['y']} and {self.get('y')}\")\n\n...\n\np = PointWithDefaults(y=6)\np.print_me()\n\np.x = 8\np.y = 4\np.print_me()\nprint()\n```\n\nNote that methods are not included in the dictionary.\nOutput:\n```\nPointWithDefaults is: {'y': 6, 'x': 0}\nPointWithDefaults X is: 0 and 0 and 0\nPointWithDefaults Y is: 6 and 6 and 6\nPointWithDefaults is: {'y': 4, 'x': 8}\nPointWithDefaults X is: 8 and 8 and 8\nPointWithDefaults Y is: 4 and 4 and 4\n```\n##### AssignmentSupportable\nOkay, i got it. But how could I use it in my custom classes?\nJust add a AssignmentSupportable to its parents! \n```code=python\nclass Figure(AssignmentSupportable):\n points: List[Point]\n\nclass NamedFigure(AssignmentSupportable):\n points_dict: Dict[str, Point]\n```\n\n```code=python\nf = Figure()\nf.points = [{ 'x': 5, 'y': 18 }, Point(x=2, y=15), dict(x=1, y=22)]\nprint(f\"Figure is: {f}\")\nprint(f\"Figure Points are: {f.points}\")\nfor i, _p in enumerate(f.points):\n print(f\"Figure Point #{i+1} is: {_p}\")\n print(f\"Figure Point #{i+1} X is: {_p.x}\")\n print(f\"Figure Point #{i+1} Y is: {_p.y}\")\nprint()\n\nf2 = NamedFigure()\nf2.points_dict = { 'A': { 'x': 5, 'y': 18 }, 'PointB': Point(x=2, y=15), 'p.C': dict(x=1, y=22) }\nprint(f\"NamedFigure is: {f2}\")\nprint(f\"NamedFigure Points are: {f2.points_dict}\")\nfor _name, _p in f2.points_dict.items():\n print(f\"NamedFigure Point '{_name}' is: {_p}\")\n print(f\"NamedFigure Point '{_name}' X is: {_p.x}\")\n print(f\"NamedFigure Point '{_name}' Y is: {_p.y}\")\nprint()\n```\nOutput:\n```\nFigure is: <__main__.Figure object at 0x7fe838cf09e8>\nFigure Points are: [{'x': 5, 'y': 18}, {'x': 2, 'y': 15}, {'x': 1, 'y': 22}]\nFigure Point #1 is: {'x': 5, 'y': 18}\nFigure Point #1 X is: 5\nFigure Point #1 Y is: 18\nFigure Point #2 is: {'x': 2, 'y': 15}\nFigure Point #2 X is: 2\nFigure Point #2 Y is: 15\nFigure Point #3 is: {'x': 1, 'y': 22}\nFigure Point #3 X is: 1\nFigure Point #3 Y is: 22\n\nNamedFigure is: <__main__.NamedFigure object at 0x7fe838cf0a58>\nNamedFigure Points are: {'A': {'x': 5, 'y': 18}, 'PointB': {'x': 2, 'y': 15}, 'p.C': {'x': 1, 'y': 22}}\nNamedFigure Point 'A' is: {'x': 5, 'y': 18}\nNamedFigure Point 'A' X is: 5\nNamedFigure Point 'A' Y is: 18\nNamedFigure Point 'PointB' is: {'x': 2, 'y': 15}\nNamedFigure Point 'PointB' X is: 2\nNamedFigure Point 'PointB' Y is: 15\nNamedFigure Point 'p.C' is: {'x': 1, 'y': 22}\nNamedFigure Point 'p.C' X is: 1\nNamedFigure Point 'p.C' Y is: 22\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/Hares/typing-tools", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "typing-tools", "package_url": "https://pypi.org/project/typing-tools/", "platform": "", "project_url": "https://pypi.org/project/typing-tools/", "project_urls": { "Homepage": "https://gitlab.com/Hares/typing-tools" }, "release_url": "https://pypi.org/project/typing-tools/0.1.4/", "requires_dist": null, "requires_python": ">=3.6.0", "summary": "Provides tools for typing in Python 3.6.", "version": "0.1.4" }, "last_serial": 4065998, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "dc719033b2a95bb4ea51eba165e757cc", "sha256": "1a0f22fd74d04dd490a148e1ca2d9f75b615ecd71909d60c924af5c298e9b868" }, "downloads": -1, "filename": "typing-tools-0.1.tar.gz", "has_sig": false, "md5_digest": "dc719033b2a95bb4ea51eba165e757cc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3255, "upload_time": "2018-05-25T13:34:21", "url": "https://files.pythonhosted.org/packages/83/02/67d739e9d57328da514d99f7d15a204fd18087984c8823d6476016c4abb1/typing-tools-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "cbaf18bc0f61dbf5a33d2b2b0fe155dc", "sha256": "cb238c8369d2113a60a198cbb3b7d4f06382b684436b29fa286f8af4ff0d48d5" }, "downloads": -1, "filename": "typing-tools-0.1.1.tar.gz", "has_sig": false, "md5_digest": "cbaf18bc0f61dbf5a33d2b2b0fe155dc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3759, "upload_time": "2018-05-28T18:58:09", "url": "https://files.pythonhosted.org/packages/58/ac/f29031c05b7de2858b9d4f653993cd37417c9c6920ea03c282c2caa31a5f/typing-tools-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "9d1e2fe18c79bb5221555bd5f4016483", "sha256": "f97f9438601280af12ada266165a76fd9f7a818c491585dd230b727b52dbaada" }, "downloads": -1, "filename": "typing-tools-0.1.2.tar.gz", "has_sig": false, "md5_digest": "9d1e2fe18c79bb5221555bd5f4016483", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4299, "upload_time": "2018-05-28T19:28:32", "url": "https://files.pythonhosted.org/packages/a5/85/219f177bb3ddc9475a8ed8ab068bea638b95024d4e1d758248f3eeb8f4a2/typing-tools-0.1.2.tar.gz" } ], "0.1.2a0": [ { "comment_text": "", "digests": { "md5": "6f0f7884e5e46819d71cd11333d63759", "sha256": "c55428f1fed365339ca62ddaa2a3df711b051fa0a51feaf2bc70f2b7217f2b83" }, "downloads": -1, "filename": "typing-tools-0.1.2a0.tar.gz", "has_sig": false, "md5_digest": "6f0f7884e5e46819d71cd11333d63759", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 7574, "upload_time": "2018-05-29T01:05:52", "url": "https://files.pythonhosted.org/packages/5f/d3/d6dccbd1ff46a329b20b846aeb0fa8e8c7eb112154a12ba81eeb647ec6e2/typing-tools-0.1.2a0.tar.gz" } ], "0.1.2b0": [ { "comment_text": "", "digests": { "md5": "6c484c4e48c6932c17f31cc9c724ed3e", "sha256": "57c07b15fe877872941cfee34ab6bfffc4a23cb4c73bada775041eed131cbe20" }, "downloads": -1, "filename": "typing-tools-0.1.2b0.tar.gz", "has_sig": false, "md5_digest": "6c484c4e48c6932c17f31cc9c724ed3e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 7563, "upload_time": "2018-05-29T01:12:12", "url": "https://files.pythonhosted.org/packages/6d/02/ff76de4cf280e64e7d23dd1f50ca2d5f66cca3ef1f7fb889eec8f359a257/typing-tools-0.1.2b0.tar.gz" } ], "0.1.2rc0": [ { "comment_text": "", "digests": { "md5": "ecbd36d35453b3c777f4b9c15bfa401a", "sha256": "08aae2e3537d1b30ff7829d75eb6518481c08a4bce69a99fc706b546e33dac55" }, "downloads": -1, "filename": "typing-tools-0.1.2rc0.tar.gz", "has_sig": false, "md5_digest": "ecbd36d35453b3c777f4b9c15bfa401a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 7546, "upload_time": "2018-05-29T01:15:19", "url": "https://files.pythonhosted.org/packages/03/6f/7fc6bd3396e81c50abc041e712f9e2124e7f5da84e108e8d5cf0f87081ae/typing-tools-0.1.2rc0.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "d2d631f8e9819b4f76894e47250cd283", "sha256": "991196448ef2fd16ff748d5197cf7e246cd77ac193e0276692d1d1ae1d127204" }, "downloads": -1, "filename": "typing-tools-0.1.3.tar.gz", "has_sig": false, "md5_digest": "d2d631f8e9819b4f76894e47250cd283", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 7604, "upload_time": "2018-06-01T14:04:57", "url": "https://files.pythonhosted.org/packages/e8/0c/962195250ff05b80dc4d403db5cbb7c501c39940b0fad18f8a73b48ee145/typing-tools-0.1.3.tar.gz" } ], "0.1.3a0": [ { "comment_text": "", "digests": { "md5": "e035fedd482f11b06a059ce5a0a699e1", "sha256": "7a787bd804bd70fd952f5c4a9ba81151dded47e37401c5089e44cce4e4286a48" }, "downloads": -1, "filename": "typing-tools-0.1.3a0.tar.gz", "has_sig": false, "md5_digest": "e035fedd482f11b06a059ce5a0a699e1", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 7608, "upload_time": "2018-05-30T19:09:33", "url": "https://files.pythonhosted.org/packages/b1/1f/22f429e9848b56def7e79902092b9e87dbd9333f602090e845f79e504e4a/typing-tools-0.1.3a0.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "43465179d3872a3fb62cc6438c17b2ff", "sha256": "45af6a297ccbdc2fc074c7a57a62a612a90ea0b77d6666b0f27a1ef9085d3095" }, "downloads": -1, "filename": "typing-tools-0.1.4.tar.gz", "has_sig": false, "md5_digest": "43465179d3872a3fb62cc6438c17b2ff", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 7609, "upload_time": "2018-07-16T14:32:18", "url": "https://files.pythonhosted.org/packages/aa/01/b3cbae1c122a0d0aae6b593582fbff16517528380d06a70eef293228d7bd/typing-tools-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "43465179d3872a3fb62cc6438c17b2ff", "sha256": "45af6a297ccbdc2fc074c7a57a62a612a90ea0b77d6666b0f27a1ef9085d3095" }, "downloads": -1, "filename": "typing-tools-0.1.4.tar.gz", "has_sig": false, "md5_digest": "43465179d3872a3fb62cc6438c17b2ff", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 7609, "upload_time": "2018-07-16T14:32:18", "url": "https://files.pythonhosted.org/packages/aa/01/b3cbae1c122a0d0aae6b593582fbff16517528380d06a70eef293228d7bd/typing-tools-0.1.4.tar.gz" } ] }