{ "info": { "author": "Fredrik Gjertsen", "author_email": "f.gjertsen@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Utilities" ], "description": "Typesys\r\n=======\r\n\r\n\r\nIntro\r\n-----\r\n\r\nTypesys is a module that is meant to make it more easy to manage types.\r\nIt contains four decorators; type_hints, type_corrector, return_type and\r\nreturns.\r\n\r\nThe *type_hints* decorator lets the user specify what the arguements of\r\na functions should be. If arguments of another type than specified in the\r\ndecorator are passed in, a TypeError will be raised.\r\n\r\nThe *type_corrector* decorator lets the user specify what types the \r\narguments to a function should have, but not necessarily are passed in as,\r\nwhich means it allows some margin of error. It's not 100% safe to use as it\r\nstill might result in a ValueError or TypeError if the user isn't careful enough.\r\n\r\nThe *return_type decorator* lets the user specify what type the decoratred\r\nfunction should return. A TypeError will be raised if the function tries to \r\nreturn a value of another type.\r\n\r\nThe *returns* decorator lets the user specify what type a function's return type \r\nhas to be (if possible to return this a value of this type). \r\n\r\nThe motivation behing this module was to abstract some of the type checking and\r\ntype casting to a higher level. I wanted to find a way that makes it easier\r\nfor the programmer to see what types the arguments should be, what a type\r\na function should return or must return, and at the same time allow some margin \r\nof error (in case of type_corrector).\r\nI'm not sure whether this is a good idea or not, or if it's a good approach.\r\nIt was mostly developed for fun while playing around with decorators.\r\n\r\n\r\nInstallation\r\n------------\r\n\r\npip install typesys\r\n\r\n\r\nBuild from source\r\n-----------------\r\n\r\nclone and run **python setup.py install**\r\n\r\n\r\nUsage\r\n-----\r\n\r\nFirst import the decorators from the typesys module:\r\n\r\n.. code:: python\r\n\r\n from typesys import type_hints, type_corrector, return_type, returns\r\n\r\nThen you are ready to start decorating your functions.\r\n\r\ntype_hints\r\n''''''''''\r\n\r\nDecorate your functions with the types you want the arguments to be, as shown in\r\nthe examples below\r\n\r\n.. code:: python\r\n \r\n # a and b must be integers\r\n @type_hints(int, int)\r\n def add(a, b):\r\n return a+b\r\n\r\n\r\n # also work with default arguments\r\n @type_hints(int, float)\r\n def add(a, b=0.0):\r\n return a+b\r\n\r\n\r\n # accepts both integers and floating \r\n # point numbers as arguments\r\n @type_hints(int, float)\r\n def mult(*numbers):\r\n result = 1\r\n for num in numbers:\r\n result *= num\r\n return result\r\n\r\n\r\n # Only accept integer arguments\r\n @type_hints(int)\r\n def mult(**kwargs):\r\n x = kwargs.get('x', 1)\r\n y = kwargs.get('y', 1)\r\n z = kwargs.get('z', 1)\r\n return x * y * z\r\n\r\n\r\n \r\ntype_corrector\r\n''''''''''''''\r\n\r\nDecorate your functions with the types you want the arguments to be treated as, \r\nbut not necessarily are passed in as, as shown in the examples below.\r\n\r\n.. code:: python\r\n\r\n @type_corrector(int, int)\r\n def add(x,y):\r\n return x+y\r\n\r\n \r\n @type_corrector(float, float)\r\n def div(x,y):\r\n return x/y\r\n \r\n\r\nA call to add(1,'2') will cast '2' to an int, since that is what we\r\nspecified as the type of the second paramater in the decorator.\r\nWe can also call div as div('10', '3'), and div will return 3.3333333333333335\r\nas expected.\r\n\r\nThis decorator also works with \\*args and \\*\\*kwargs\r\n\r\n.. code:: python\r\n\r\n @type_corrector(int)\r\n def mult(*numbers):\r\n result = 1\r\n for num in numbers:\r\n result *= num\r\n return result\r\n\r\n\r\n @type_corrector(int)\r\n def mult(**kwargs):\r\n x = kwargs.get('x', 1)\r\n y = kwargs.get('y', 1)\r\n z = kwargs.get('z', 1)\r\n return x * y * z \r\n\r\n\r\nThis allows us to call the functions like this:\r\n\r\n- mult(2, '3', '4') \r\n- kw_mult(x=2, y='3', z='4')\r\n\r\nWhen looking at the function definitions of add, mult and kw_mult we can easily\r\nsee that the arguments are supposed to be integers.\r\nBy decorating the functions like this it should also be a clear\r\nhint what types we want the arguments to be passed in as, even though it \r\nallows some margin of error.\r\n\r\n\r\nreturn_type\r\n'''''''''''\r\n\r\nDecorate your functions with the type or types you want your functions to\r\nreturn, as shown in the examples below.\r\n\r\n.. code:: python\r\n \r\n # accepts both integers, floatint point numbers \r\n # and complex numbers to be returned\r\n @return_type(int, float, complex)\r\n def add(x,y):\r\n return x+y\r\n\r\n\r\n # only accept integers to be returned\r\n @return_type(int)\r\n def strict_add(x,y):\r\n return x+y\r\n\r\n\r\nThe same applies for functions defined with \\*args and/or \\*\\*kwargs\r\n\r\n.. code:: python\r\n\r\n # accepts both integers and floating point numbers\r\n # to be returned\r\n @return_type(int, float)\r\n def mult(*numbers):\r\n res = 1\r\n for number in numbers:\r\n res *= number\r\n return res\r\n\r\n\r\n # only accepts integers to be returned\r\n @return_type(int)\r\n def stric_kw_mult(**kwargs):\r\n x = kwargs.get('x', 1)\r\n y = kwargs.get('y', 1)\r\n z = kwargs.get('z', 1)\r\n return x * y * z\r\n\r\n\r\nreturns\r\n'''''''\r\n\r\nDecorate your functions with the type your funcitons must return, as long as\r\nit's possible.\r\n\r\n.. code:: python\r\n\r\n # returns x+y as a string\r\n @returns(str)\r\n def add(x,y):\r\n return x+y\r\n \r\n\r\nA call to add(1,2) will return the number 3 as a string.\r\n\r\n\r\nKnown issues\r\n------------\r\n\r\n- When calling help on a decorated function the parameters are not shown\r\n correctly, instead it will just say (\\*args, \\*\\*kwargs).\r\n Thanks to the functools.wraps decorator the docstring of a decorated function\r\n will still be shown correctly.\r\n- When using the inspect module to get the argument specification with\r\n inspect.getargspec or getting the source code from inspect.getsourcelines\r\n it will fail and show the wrapped function instead.\r\n\r\n\r\nBugs, problems and new features\r\n-------------------------------\r\n\r\nIf you find any bugs, have any problems, or maybe you just want to request a \r\nnew feature, then use the `issue tracker\r\n`_.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/fredgj/typesys", "keywords": "types,type hints,type hinting,type correction,typesystem,typesys", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "typesys", "package_url": "https://pypi.org/project/typesys/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/typesys/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/fredgj/typesys" }, "release_url": "https://pypi.org/project/typesys/0.2.9/", "requires_dist": null, "requires_python": null, "summary": "typesys is a python module meant to make it easier to manange types", "version": "0.2.9" }, "last_serial": 1699919, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "aa8824fc8b76101ec72d26e1d65d4138", "sha256": "d247aabc2b768f5caa06a9d920bf760f573865a04724870c9fdc2e11ba3a90d9" }, "downloads": -1, "filename": "typesys-0.1.0.tar.gz", "has_sig": false, "md5_digest": "aa8824fc8b76101ec72d26e1d65d4138", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5122, "upload_time": "2015-07-31T01:24:38", "url": "https://files.pythonhosted.org/packages/fe/56/c4ed9e44faa87f7ff74d1629d87f641b8e1c295f6859da0d2a8663675861/typesys-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "d705113250bed1078a99c8f216695d70", "sha256": "5d253cd04c669c9105fb6890d44d24cc3f21a9e62e8d128df3ead648a9bea7f8" }, "downloads": -1, "filename": "typesys-0.2.0.tar.gz", "has_sig": false, "md5_digest": "d705113250bed1078a99c8f216695d70", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5125, "upload_time": "2015-07-31T01:37:33", "url": "https://files.pythonhosted.org/packages/a9/46/d3d65a733b6e08293ae7eef1bff9b02d04a726f097e38ef0f95aa6b1c659/typesys-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "8bac1cc8e9722526b16b9efb993ecdea", "sha256": "84e5067b8b3987d7a2551013003787dfae88aca8dac536f412cf63b864d21938" }, "downloads": -1, "filename": "typesys-0.2.1.tar.gz", "has_sig": false, "md5_digest": "8bac1cc8e9722526b16b9efb993ecdea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5125, "upload_time": "2015-07-31T01:40:33", "url": "https://files.pythonhosted.org/packages/4f/dc/87f546e92eeb523ce0b81176c590554f2fb0bb36ed836fe8d5ab17226fe7/typesys-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "48fb0c0063f45cf98b314376cba90c10", "sha256": "76263f81d8947f70cd9de43acda8f185402774811a468ecf94355a356d1ed0a3" }, "downloads": -1, "filename": "typesys-0.2.2.tar.gz", "has_sig": false, "md5_digest": "48fb0c0063f45cf98b314376cba90c10", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5120, "upload_time": "2015-07-31T01:58:12", "url": "https://files.pythonhosted.org/packages/09/c2/105a0bac20f464db53227de65c46700191b65f3ecde213bee42b13139a06/typesys-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "79db14bbb68fd826f48b885ec95474a9", "sha256": "7ade5d845b7ffd367ccbd646d49e9f8b1cc72bafe31e3e2ba2a976ebf081c3ef" }, "downloads": -1, "filename": "typesys-0.2.3.tar.gz", "has_sig": false, "md5_digest": "79db14bbb68fd826f48b885ec95474a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5120, "upload_time": "2015-07-31T03:05:28", "url": "https://files.pythonhosted.org/packages/90/3c/02b9ce9c1c0e1360978ab9e409a305d8e31b3c12d81e52874c9bbede2d91/typesys-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "138b1a000ed6721bc1d9b3db7b046c3a", "sha256": "7450af212b682febe554193a3f9d554c478cb4c2a8506a3ec400b6bb9d35a7ac" }, "downloads": -1, "filename": "typesys-0.2.4.tar.gz", "has_sig": false, "md5_digest": "138b1a000ed6721bc1d9b3db7b046c3a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5119, "upload_time": "2015-07-31T13:15:18", "url": "https://files.pythonhosted.org/packages/f8/8d/400aa1db8c37dd64d8ff908279d76cda328910744cd51adecfad91ae9717/typesys-0.2.4.tar.gz" } ], "0.2.5": [ { "comment_text": "", "digests": { "md5": "dabca4e9be7adccfe86b09c8048517ed", "sha256": "9cb6c9c6aad5e4a4b599221b52afd135ba4ee44abcace82786f89c996d74d7c0" }, "downloads": -1, "filename": "typesys-0.2.5.tar.gz", "has_sig": false, "md5_digest": "dabca4e9be7adccfe86b09c8048517ed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5116, "upload_time": "2015-07-31T13:50:52", "url": "https://files.pythonhosted.org/packages/45/32/cacbf5d4806512a218bf4055954587ca358c72f7fccfd3ec702691cebefa/typesys-0.2.5.tar.gz" } ], "0.2.6": [ { "comment_text": "", "digests": { "md5": "891a75df39f66a8176df5bee846dee20", "sha256": "911e6becac1525d9dc6b444888996907a30d7ed2d1ff3b33f61cdc453f44685e" }, "downloads": -1, "filename": "typesys-0.2.6.tar.gz", "has_sig": false, "md5_digest": "891a75df39f66a8176df5bee846dee20", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5384, "upload_time": "2015-07-31T22:54:37", "url": "https://files.pythonhosted.org/packages/f7/ef/32b695fc4018b667a00eeb624019919a1bc7a731d0e7bacb3269c45a5837/typesys-0.2.6.tar.gz" } ], "0.2.7": [ { "comment_text": "", "digests": { "md5": "591a017f22776cf7e8615d915db793e0", "sha256": "c9f3d17852c80ac0ba6e101da3d73c2c9223916eeb252be33ea2ad5c505e99d4" }, "downloads": -1, "filename": "typesys-0.2.7.tar.gz", "has_sig": false, "md5_digest": "591a017f22776cf7e8615d915db793e0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5306, "upload_time": "2015-08-01T01:52:23", "url": "https://files.pythonhosted.org/packages/a0/f4/0dd48fca0bdb7d329f75577f27a224ceaca19d19f9110133d4c277c20729/typesys-0.2.7.tar.gz" } ], "0.2.8": [ { "comment_text": "", "digests": { "md5": "8991bbb7e2199d49672d7a3a77b6210a", "sha256": "1a1c30fcf61469439e288ccd2074e0b74bc5f2981fe7062826f273507477db33" }, "downloads": -1, "filename": "typesys-0.2.8.tar.gz", "has_sig": false, "md5_digest": "8991bbb7e2199d49672d7a3a77b6210a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5840, "upload_time": "2015-08-02T14:19:30", "url": "https://files.pythonhosted.org/packages/8d/72/965ce528c89bad6eff04bd3b1742b68c793eecf6d7829a5da487e464312b/typesys-0.2.8.tar.gz" } ], "0.2.9": [ { "comment_text": "", "digests": { "md5": "4f6bc95235768df589b9889fb00cf8d0", "sha256": "55f4614190cd71a28e645ec814050fbcb3d7d71bb1cf836a196fa6f8f4ec839a" }, "downloads": -1, "filename": "typesys-0.2.9.tar.gz", "has_sig": false, "md5_digest": "4f6bc95235768df589b9889fb00cf8d0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5871, "upload_time": "2015-08-12T23:04:24", "url": "https://files.pythonhosted.org/packages/12/d8/4e5dfba9fffd3229b0c230f35a0251eec158e1521b88925830d6d59e7ccf/typesys-0.2.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4f6bc95235768df589b9889fb00cf8d0", "sha256": "55f4614190cd71a28e645ec814050fbcb3d7d71bb1cf836a196fa6f8f4ec839a" }, "downloads": -1, "filename": "typesys-0.2.9.tar.gz", "has_sig": false, "md5_digest": "4f6bc95235768df589b9889fb00cf8d0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5871, "upload_time": "2015-08-12T23:04:24", "url": "https://files.pythonhosted.org/packages/12/d8/4e5dfba9fffd3229b0c230f35a0251eec158e1521b88925830d6d59e7ccf/typesys-0.2.9.tar.gz" } ] }