{ "info": { "author": "Aric Coady", "author_email": "aric.coady@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "[![image](https://img.shields.io/pypi/v/multimethod.svg)](https://pypi.org/project/multimethod/)\n[![image](https://img.shields.io/pypi/pyversions/multimethod.svg)](https://python3statement.org)\n[![image](https://pepy.tech/badge/multimethod)](https://pepy.tech/project/multimethod)\n![image](https://img.shields.io/pypi/status/multimethod.svg)\n[![image](https://img.shields.io/travis/coady/multimethod.svg)](https://travis-ci.org/coady/multimethod)\n[![image](https://img.shields.io/codecov/c/github/coady/multimethod.svg)](https://codecov.io/github/coady/multimethod)\n[![image](https://readthedocs.org/projects/multimethod/badge)](https://multimethod.readthedocs.io)\n[![image](https://requires.io/github/coady/multimethod/requirements.svg)](https://requires.io/github/coady/multimethod/requirements/)\n[![image](https://api.codeclimate.com/v1/badges/5a3ddcd54e550eee27f9/maintainability)](https://codeclimate.com/github/coady/multimethod/maintainability)\n[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)\n\nMultimethod provides a decorator for adding multiple argument dispatching to functions.\nThe decorator finds the multimethod of the same name, creating it if necessary,\nand registers the function with its annotations.\n\nThere are several multiple dispatch libraries on PyPI.\nThis one aims for simplicity and speed. With caching of argument types,\nit should be the fastest pure Python implementation possible.\n\n# Usage\n## multimethod\n```python\nfrom multimethod import multimethod\n\n@multimethod\ndef func(x: int, y: float):\n ...\n```\n\n`func` is now a `multimethod` which will delegate to the above function,\nwhen called with arguments of the specified types.\nSubsequent usage will register new types and functions to the existing multimethod of the same name.\nIf an exact match isn't registered, the next closest method is called (and cached).\nCandidate methods are ranked based on their subclass relationships.\nIf no matches are found, a custom `TypeError` is raised.\n\nA `strict` flag can also be set on the `multimethod` object,\nin which case finding multiple matches also raises a `TypeError`.\nKeyword arguments can be used when calling, but won't affect the dispatching.\nIf no annotations are specified, it will inherently match any aruments.\n\nMultimethods are implemented as mappings from signatures to functions,\nand can be introspected as such.\n\n```python\nmethod[type, ...] # get registered function\nmethod[type, ...] = func # register function by explicit types\nmethod.register(func) # decorator to register annotated function (with any __name__)\n```\n\nMultimethods support any types that satisfy the `issubclass` relation,\nincluding abstract base classes in `collections` and `typing`.\n\n## multidispatch\nThe [functools.singledispatch](https://docs.python.org/3/library/functools.html#functools.singledispatch)\nstyle syntax is also supported. This requires creating a `multidispatch` object explicitly,\nand consequently doesn't rely on the name matching.\nThe `register` method returns a decorator for given types,\nthereby supporting [Python 2](https://python3statement.org) and stacking of multiple signatures.\n\n```python\nfrom multimethod import multidispatch\n\n@multidispatch\ndef func(*args):\n ...\n\n@func.register(object, int)\n@func.register(int, object)\ndef _(*args):\n ...\n```\n\n## overload\nOverloads dispatch on annotated predicates.\nEach predicate is checked in the reverse order of registration.\n\nThe implementation is separate from `multimethod` due to the different performance characteristics.\nInstead a simple `isa` predicate is provided for checking instance type.\n\n```python\nfrom multimethod import isa, overload\n\n@overload\ndef func(obj: isa(str)):\n ...\n\n@overload\ndef func(obj: str.isalnum):\n ...\n\n@overload\ndef func(obj: str.isdigit):\n ...\n```\n\n## multimeta\n\nIn Python 3, use `metaclass=multimeta` to create a class with a special namespace which converts callables to multimethods, and registers duplicate callables with the original.\n\n```python\nfrom multimethod import multimeta\n\nclass Foo(metaclass=multimeta):\n def bar(self, x: str):\n ...\n\n def bar(self, x: int):\n ...\n```\n\nEquivalent to:\n\n```python\nfrom multimethod import multimethod\n\nclass Foo:\n @multimethod\n def bar(self, x: str):\n ...\n\n @bar.register\n def bar(self, x: int):\n ...\n```\n\n# Installation\n\n $ pip install multimethod\n\n# Tests\n100% branch coverage.\n\n $ pytest [--cov]\n\n# Changes\n1.1\n* Fix for Python 2 typing backport\n* Metaclass for automatic multimethods\n\n1.0\n* Missing annotations default to object\n* Removed deprecated dispatch stacking\n\n0.7\n* Forward references allowed in type hints\n* Register method\n* Overloads with predicate dispatch\n\n0.6\n* Multimethods can be defined inside a class\n\n0.5\n* Optimized dispatching\n* Support for `functools.singledispatch` syntax\n\n0.4\n* Dispatch on Python 3 annotations\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/coady/multimethod", "keywords": "multiple dispatch multidispatch generic functions methods overload", "license": "Apache Software License", "maintainer": "", "maintainer_email": "", "name": "multimethod", "package_url": "https://pypi.org/project/multimethod/", "platform": "", "project_url": "https://pypi.org/project/multimethod/", "project_urls": { "Documentation": "https://multimethod.readthedocs.io", "Homepage": "https://github.com/coady/multimethod" }, "release_url": "https://pypi.org/project/multimethod/1.1/", "requires_dist": [ "m2r ; extra == 'docs'", "nbsphinx ; extra == 'docs'", "jupyter ; extra == 'docs'" ], "requires_python": ">=2.7", "summary": "Multiple argument dispatching.", "version": "1.1" }, "last_serial": 5412727, "releases": { "0.4": [ { "comment_text": "", "digests": { "md5": "f11fa3a710f8ecd4ec592c3fdd9a131f", "sha256": "30848df6a30cd904559430bfd001e97a385f4642d2bde1ca2ebf61c9582682ba" }, "downloads": -1, "filename": "multimethod-0.4.tar.gz", "has_sig": false, "md5_digest": "f11fa3a710f8ecd4ec592c3fdd9a131f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3691, "upload_time": "2013-11-11T01:41:43", "url": "https://files.pythonhosted.org/packages/50/ce/df57c06de38fc75f53548d96a62daafb9e84c4f82c1e2b682760ce0d20f3/multimethod-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "7518a41e38e351d69df52d2e03cbcf92", "sha256": "2ddba71265cb51dfd3d078b86b2bf57d47426ccf810bd2a695dfcce75526083d" }, "downloads": -1, "filename": "multimethod-0.5.tar.gz", "has_sig": false, "md5_digest": "7518a41e38e351d69df52d2e03cbcf92", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4343, "upload_time": "2015-09-04T00:18:11", "url": "https://files.pythonhosted.org/packages/c1/3c/65ea1ca4f580ec9224c4d0c85cba9b0b440971e2aea147cbbb1c8115681d/multimethod-0.5.tar.gz" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "a79b6c7a86614e8eaf1acbb52e38e633", "sha256": "d6e57443e877b9c565eff107de760029e78c7432286cbad155ae1ec0b918f1dd" }, "downloads": -1, "filename": "multimethod-0.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a79b6c7a86614e8eaf1acbb52e38e633", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5856, "upload_time": "2017-01-02T19:02:52", "url": "https://files.pythonhosted.org/packages/ff/f6/ac4366395cd56dd562503c795da6fc4ab72a4d23007418c1d5263f1f3193/multimethod-0.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "db4f0bf1bf2497e764ea99ddcabdf22a", "sha256": "8bcd126f109ba22bcfa32053f0b56c6676204e241df0907198cbaf62326f1c7c" }, "downloads": -1, "filename": "multimethod-0.6.tar.gz", "has_sig": false, "md5_digest": "db4f0bf1bf2497e764ea99ddcabdf22a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5144, "upload_time": "2017-01-02T19:02:50", "url": "https://files.pythonhosted.org/packages/23/a9/b463846378a17efcacc5e2bd5189035776a3cb0c00f643a75ffe7beb49c2/multimethod-0.6.tar.gz" } ], "0.7": [ { "comment_text": "", "digests": { "md5": "a1a92b345184c5ae0bf94d619ddacd96", "sha256": "0c0efff31315fd5f9716e68c6b94955187462ae0a5861a7494f51dc63081c052" }, "downloads": -1, "filename": "multimethod-0.7-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a1a92b345184c5ae0bf94d619ddacd96", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=2.7, >=3.4", "size": 7122, "upload_time": "2017-12-08T01:38:02", "url": "https://files.pythonhosted.org/packages/29/e8/8c1c31b246a1434d7860936a49dd2e7e74f6fb5f169b6e288308b3f37adf/multimethod-0.7-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ea9056e87834f5c6cf6c138cae4f0252", "sha256": "5748e620aa50d95843b0fda0e47cd616227df8ff58bafdeae9393852a93a5d47" }, "downloads": -1, "filename": "multimethod-0.7.tar.gz", "has_sig": false, "md5_digest": "ea9056e87834f5c6cf6c138cae4f0252", "packagetype": "sdist", "python_version": "source", "requires_python": "~=2.7, >=3.4", "size": 6554, "upload_time": "2017-12-08T01:38:03", "url": "https://files.pythonhosted.org/packages/5c/29/f8b101ed29ac77e7298b57600550c8f211e02179785581eff7d0a6728a41/multimethod-0.7.tar.gz" } ], "0.7.1": [ { "comment_text": "", "digests": { "md5": "79d9074fc3a46055c9fb8e2957536301", "sha256": "726cd6a07f68c5e0fdb504983ccb6cf9ce10cea58cad67195cc99ea84169f941" }, "downloads": -1, "filename": "multimethod-0.7.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "79d9074fc3a46055c9fb8e2957536301", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7", "size": 7102, "upload_time": "2017-12-12T02:40:14", "url": "https://files.pythonhosted.org/packages/9f/cc/c27b64aebe905be8ea57841a04c67e8fcc528e41568ff5b4aab146b18a3d/multimethod-0.7.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "95bfb1a98e170291fe4ba9a2c50876f5", "sha256": "53846b22601ea4992954cb10ab30f47ac26d34c73478af2e2e32bf68b7f7cb0b" }, "downloads": -1, "filename": "multimethod-0.7.1.tar.gz", "has_sig": false, "md5_digest": "95bfb1a98e170291fe4ba9a2c50876f5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 6535, "upload_time": "2017-12-12T02:40:16", "url": "https://files.pythonhosted.org/packages/13/b1/4a16ffb5b793547de6cf51ce0906258586f7cc45ed073bee01c43299747f/multimethod-0.7.1.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "1395b54d4f5b04c20210e32c4af73a53", "sha256": "5f20db508dfb95aa2b135299a436a68342ccfc2c275b6636b6306de435c01d66" }, "downloads": -1, "filename": "multimethod-1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1395b54d4f5b04c20210e32c4af73a53", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7", "size": 5226, "upload_time": "2018-12-07T23:52:14", "url": "https://files.pythonhosted.org/packages/d0/98/4c9a1fe8c0383e944efcb0e9b157ea253f49ec691f310c484b1a8b8585d5/multimethod-1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fb6cdc2368e9893564c69aefadd6293a", "sha256": "2749fca0e36c817be90fa62ca10d60c6fd8d09dcec65aca33be0e7a1e82b8ecb" }, "downloads": -1, "filename": "multimethod-1.0.tar.gz", "has_sig": false, "md5_digest": "fb6cdc2368e9893564c69aefadd6293a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 6461, "upload_time": "2018-12-07T23:52:16", "url": "https://files.pythonhosted.org/packages/40/ac/0195b2ae0665e221c40e2a9200bb19f643ef256e9b5d4108d51c0165b284/multimethod-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "725910029ec93929072cee2a81a79451", "sha256": "f15271ebd98ac5d4bd1bc7445d0b71d134d4642d62f253711774733943d499ef" }, "downloads": -1, "filename": "multimethod-1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "725910029ec93929072cee2a81a79451", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7", "size": 5650, "upload_time": "2019-06-18T00:37:01", "url": "https://files.pythonhosted.org/packages/4f/9c/c321effe4a47e92b3a7fcd72f1375300d2b38138ec77b4f5afd84b8e0755/multimethod-1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0abfa8976e4f58783fc8e35cb43fce46", "sha256": "afdc836df012b26350e38539b9cb026d62240bb293a95bccf7dbfde1a49e3bc9" }, "downloads": -1, "filename": "multimethod-1.1.tar.gz", "has_sig": false, "md5_digest": "0abfa8976e4f58783fc8e35cb43fce46", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 7123, "upload_time": "2019-06-18T00:37:03", "url": "https://files.pythonhosted.org/packages/b5/c1/79cd89b6a3fa6ee562346a80b9db40784f4d596d9acb427fed92bc9bf48c/multimethod-1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "725910029ec93929072cee2a81a79451", "sha256": "f15271ebd98ac5d4bd1bc7445d0b71d134d4642d62f253711774733943d499ef" }, "downloads": -1, "filename": "multimethod-1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "725910029ec93929072cee2a81a79451", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7", "size": 5650, "upload_time": "2019-06-18T00:37:01", "url": "https://files.pythonhosted.org/packages/4f/9c/c321effe4a47e92b3a7fcd72f1375300d2b38138ec77b4f5afd84b8e0755/multimethod-1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0abfa8976e4f58783fc8e35cb43fce46", "sha256": "afdc836df012b26350e38539b9cb026d62240bb293a95bccf7dbfde1a49e3bc9" }, "downloads": -1, "filename": "multimethod-1.1.tar.gz", "has_sig": false, "md5_digest": "0abfa8976e4f58783fc8e35cb43fce46", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 7123, "upload_time": "2019-06-18T00:37:03", "url": "https://files.pythonhosted.org/packages/b5/c1/79cd89b6a3fa6ee562346a80b9db40784f4d596d9acb427fed92bc9bf48c/multimethod-1.1.tar.gz" } ] }