{ "info": { "author": "ben avrahami", "author_email": "dontcallme@illcall.you", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9" ], "description": "# Dyndis\n\n[`pip install dyndis`](https://pypi.org/project/dyndis/)\n\n## About\n\nDyndis is a library to easily and fluently make multiple-dispatch functions and methods. It was originally made for\noperators in non-strict hierarchical systems but can also serve any other multiple-dispatch purpose.\n\n## Simple Example\n\n```python\nfrom typing import Union\n\nfrom dyndis import MultiDispatch\n\n\n@MultiDispatch\ndef foo(a, b):\n # default implementation in case no candidates match\n raise TypeError\n\n\n@foo.register()\ndef _(a: int, b: Union[int, str]):\n return \"overload 1 \"\n\n\n@foo.register()\ndef _(a: object, b: float):\n return \"overload 2 \"\n\n\nfoo(1, \"hello\") # overload 1\nfoo((\"any\", \"object\", \"here\"), 2.5) # overload 2\nfoo(2, 3) # overload 1\nfoo(2, 3.0) # overload 2\n```\n\n## Features\n\n* dynamic upcasting.\n* seamless usage of type-hints and type variables.\n* advanced data structures to minimize candidate lookup time.\n* implementor interface makes it easy to create method-like overloads\n\n## How Does it Work?\n\nThe central class (and only one users need to import) is `MultiDispatch`. `MultiDispatch` contains candidate\nimplementations sorted by both priority and types of the parameters they accept. When the `MultiDispatch` is called, it\ncalls its relevant candidates (ordered by both priority, inheritance, and compatibility, expanded upon below) until one\nreturns a non-`NotImplemented` return value.\n\n## The Lookup Order\n\nAll candidates for parameters of types are ordered as follows:\n\n* Any candidate with a types that is incompatible with any type in the key is excluded. That is, if for any 0 <= `i` <=\n N, a candidate's type constraint for parameter `i` is not a superclass of Ti, the candidate is excluded.\n* Candidates are ordered by inheritance. A candidate is considered to inherit another candidate if all its parameter\n types are subclasses of (or are likewise covered by) the other's respective parameter type. A candidate will be\n considered before any other candidate it inherits. So for example, will be considered before .\n\nIf there are two candidates that do not inherit each other, an exception (of type `dyndis.AmbiguityError`) is raised (\nunless a candidate with greater precedence than both succeeds first).\n\nIf a candidate returns `NotImplemented`, the next candidate in the order is tried. If no candidates are accepted or all\ncandidates returned `NotImplemented`, the default implementation is called.\n\n## Topology and Caches\n\n`dyndis` uses a topological set to order all its candidates by the parameter types, so that most of the candidates can\nbe disregarded without any overhead.\n\nConsidering all these candidates for every lookup gets quite slow and encumbering very quickly. For this reason,\nevery `MultiDispatch` automatically caches these computation for both sorting and processing candidates.\n\n## Default, Variadic, and Keyword parameters\n\n* If a candidate has positional parameters with a default value and a type annotation, the default value will be ignored\n for the purposes of candidate resolution.\n* If a candidate has a variadic positional parameter, it is ignored. When called from a `MultiDispatch`, its value will\n always be `()`.\n* If a candidate has keyword-only parameters, the parameter will not be considered for candidate types, it must either\n have a default value or be set when the `MultiDispatch` is called.\n* If a candidate has a variadic keyword parameter, it is ignored. When called from a `MultiDispatch`, its value will be\n according to the (type-ignored) keyword arguments.\n\nIn general, when a `MultiDispatch` is called with keyword arguments, those arguments are not considered for candidate\nresolution and are sent to each attempted candidate as-is.\n\n## Implementors\n\nan `Implementor` is a descriptor that makes it easy to create method-like candidates inside classes.\n\n```python\nfrom dyndis import MultiDispatch\n\n\n@MultiDispatch\ndef add(self, other):\n return NotImplemented\n\n\nclass Base:\n __add__ = add\n\n\nclass A(Base):\n @add.implement(__qualname__)\n def add(self, other: 'A'):\n # in implementor methods, `self` is assumed to be of the owner class\n return \"A+A\"\n\n @add.implement(__qualname__)\n def add(self, other: Base):\n return \"A+Base\"\n\n\nclass B(Base):\n @add.implement(__qualname__)\n def add(self, other: A):\n return 'B+A'\n\n\na = A()\nb = B()\nbase = Base()\na + b # A+B\na + base # A+Base\na + a # A+A\n```\n\n## Special Type Annotations\n\ntype annotations can be of any type, or among any of these special values\n\n* `typing.Union`: accepts parameters of any of the enclosed type\n* `typing.Optional`: accepts the enclosed type or `None`\n* `typing.Any`: is considered a supertype for any type, including `object`\n* Any of typing's aliases and abstract classes such as `typing.List` or `typing.Sized`: equivalent to their origin\n type (note that specialized aliases such as `typing.List[str]` are invalid)\n* `typing.TypeVar`: see below\n* `None`, `...`, `NotImplemented`: equivalent to their types\n\n## `TypeVar` annotations\n\nParameters can also be annotated with `typing.TypeVar`s. These variables bind greedily as they are encountered, and\ncount as matched upon first binding. After first binding, they are treated as the bound type (or the lowest constraint\nof the `TypeVar`) for all respects.\n\n```python\nfrom typing import TypeVar, Any\n\nfrom dyndis import MultiDispatch\n\nT = TypeVar('T')\n\n\n@MultiDispatch\ndef foo(*args):\n raise TypeError\n\n\n@foo.register()\ndef _(a: T, b: T):\n return \"type(b) <= type(a)\"\n\n\n@foo.register()\ndef _(a: Any, b: Any):\n return \"type(b) =3.7,<4.0", "summary": "", "version": "0.2.0", "yanked": false, "yanked_reason": null }, "last_serial": 8947188, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "9ca048a220123fea6de2ed5f6ce96b6f", "sha256": "bf41fdd88272dd0adf9e8b13d151c3a16ca2bca254cf6e66f1304fea2b4dd36e" }, "downloads": -1, "filename": "dyndis-0.0.1.win-amd64.zip", "has_sig": false, "md5_digest": "9ca048a220123fea6de2ed5f6ce96b6f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 19993, "upload_time": "2019-10-28T08:01:40", "upload_time_iso_8601": "2019-10-28T08:01:40.324698Z", "url": "https://files.pythonhosted.org/packages/f5/05/d2864f6e0e08182d77009a087e91a91891db2aab35dfc480f7eaf22c11c2/dyndis-0.0.1.win-amd64.zip", "yanked": false, "yanked_reason": null } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "fbb957990916331ea332da0dd054a554", "sha256": "a0717453849e2c3a3d6f798a81c0dc9d131ab4851d36afa9904c4a8f83ee73ec" }, "downloads": -1, "filename": "dyndis-0.0.2.tar.gz", "has_sig": false, "md5_digest": "fbb957990916331ea332da0dd054a554", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 11654, "upload_time": "2019-10-30T14:27:00", "upload_time_iso_8601": "2019-10-30T14:27:00.102004Z", "url": "https://files.pythonhosted.org/packages/d5/e7/bce1da7f51cb62d76dae15af1f3b9794223268f1e15460d475f1647afb24/dyndis-0.0.2.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.2.dev0": [ { "comment_text": "", "digests": { "md5": "3bd47d2f27a299945d78d0a6259693dc", "sha256": "e27753f1a0d3ffea3409ef534ea706806d33c8ae65221e09effeb0b53134f722" }, "downloads": -1, "filename": "dyndis-0.0.2.dev0.tar.gz", "has_sig": false, "md5_digest": "3bd47d2f27a299945d78d0a6259693dc", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 5743, "upload_time": "2019-10-28T08:06:11", "upload_time_iso_8601": "2019-10-28T08:06:11.268717Z", "url": "https://files.pythonhosted.org/packages/4f/f0/caca12f7745a093c5c4836c824057c9f3347cdfbe7648521c7fc9bf445d6/dyndis-0.0.2.dev0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.2.post1": [ { "comment_text": "", "digests": { "md5": "c27ee6064fceeca916eb79eec1b16bd1", "sha256": "fd8b49bf012085408159d23ce3e1869e7656151829e233c7dad4c4e4b7226003" }, "downloads": -1, "filename": "dyndis-0.0.2.post1.tar.gz", "has_sig": false, "md5_digest": "c27ee6064fceeca916eb79eec1b16bd1", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 11705, "upload_time": "2019-10-31T08:58:14", "upload_time_iso_8601": "2019-10-31T08:58:14.468058Z", "url": "https://files.pythonhosted.org/packages/10/4f/2d754e2014941a41d0f93ca96606f8be4c45e6f8c09b5537d6ed5b21429d/dyndis-0.0.2.post1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.2.post2": [ { "comment_text": "", "digests": { "md5": "ad20708b9a9028d4867dff2c08ad5f93", "sha256": "8028a35a3d821bb8b7ddac2e1eea158b0e817887152b2d13936009766f33d48b" }, "downloads": -1, "filename": "dyndis-0.0.2.post2.tar.gz", "has_sig": false, "md5_digest": "ad20708b9a9028d4867dff2c08ad5f93", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 11685, "upload_time": "2019-10-31T08:59:43", "upload_time_iso_8601": "2019-10-31T08:59:43.766782Z", "url": "https://files.pythonhosted.org/packages/6d/02/21e01a9e7a85303fa4604fd2f189c723ab7370b9abf9a7a0037d00b01052/dyndis-0.0.2.post2.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.2.post3": [ { "comment_text": "", "digests": { "md5": "88b63d206c6ae634d0c7c919f5b10654", "sha256": "f0b36e41f57f87e836532062dce6a1ef2d17a7c786918b4fc171eed7782e1b71" }, "downloads": -1, "filename": "dyndis-0.0.2.post3.tar.gz", "has_sig": false, "md5_digest": "88b63d206c6ae634d0c7c919f5b10654", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 11705, "upload_time": "2019-10-31T09:05:58", "upload_time_iso_8601": "2019-10-31T09:05:58.280752Z", "url": "https://files.pythonhosted.org/packages/9b/45/9395c87f06d66ff39757a95f9ab59aebfe8928e976d5ae90a19c448353c7/dyndis-0.0.2.post3.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.2.post4": [ { "comment_text": "", "digests": { "md5": "39e1caae03909ce4c7ba1cd2197fcaa4", "sha256": "7c311246d804546481bbe7d17a6664b0c966581695ad7706aa074f530cb8dc7c" }, "downloads": -1, "filename": "dyndis-0.0.2.post4.tar.gz", "has_sig": false, "md5_digest": "39e1caae03909ce4c7ba1cd2197fcaa4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 11722, "upload_time": "2019-10-31T09:12:01", "upload_time_iso_8601": "2019-10-31T09:12:01.269210Z", "url": "https://files.pythonhosted.org/packages/4e/a4/21d63cb218e7281b6d29f3fe3d57acab519203b344bd263f3029504ce5e1/dyndis-0.0.2.post4.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.3.post0": [ { "comment_text": "", "digests": { "md5": "6a27268cfdfb8ac40ec8dd827a933217", "sha256": "91b13862814bc32a841cd745bd51c19fbc624c45215b699763602ea4fe783e81" }, "downloads": -1, "filename": "dyndis-0.0.3.post0.tar.gz", "has_sig": false, "md5_digest": "6a27268cfdfb8ac40ec8dd827a933217", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 12546, "upload_time": "2019-11-11T09:59:15", "upload_time_iso_8601": "2019-11-11T09:59:15.581118Z", "url": "https://files.pythonhosted.org/packages/fa/c8/aba3c57dad93e76baaad3b6521dcc7fb22a105388f652caaaee438f53d3d/dyndis-0.0.3.post0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.3b0": [ { "comment_text": "", "digests": { "md5": "530e8a41aeafca5ea2d9b3c1dd802346", "sha256": "fc25ce461de19dbcf435308775f96afef6d7c2c5f38085046d2314b843d4abab" }, "downloads": -1, "filename": "dyndis-0.0.3b0.tar.gz", "has_sig": false, "md5_digest": "530e8a41aeafca5ea2d9b3c1dd802346", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 12306, "upload_time": "2019-10-31T12:42:16", "upload_time_iso_8601": "2019-10-31T12:42:16.310553Z", "url": "https://files.pythonhosted.org/packages/73/35/bd6bef2fb4a21ff0de2c0231d198389b3f148f19ad143f4c6e6ff49ef9d2/dyndis-0.0.3b0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.3b1": [ { "comment_text": "", "digests": { "md5": "534c79ef8fa43763de94642095f039f8", "sha256": "03340f931a1d114d0a439edd9e73465c6a82eb1382d7a466ab11c85d815f7611" }, "downloads": -1, "filename": "dyndis-0.0.3b1.tar.gz", "has_sig": false, "md5_digest": "534c79ef8fa43763de94642095f039f8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 12506, "upload_time": "2019-11-04T12:56:32", "upload_time_iso_8601": "2019-11-04T12:56:32.916424Z", "url": "https://files.pythonhosted.org/packages/14/1d/02ad4d0fbe3c26ff80792d1a4c7ccca6051691373c1d370c4e9b5118a2f8/dyndis-0.0.3b1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.3b1.post0": [ { "comment_text": "", "digests": { "md5": "f059e87027b764ba28baf389f8d17443", "sha256": "3f7847b552a53e522b8e97749ae98c86bf2cea083ab4266229f25e37514c0feb" }, "downloads": -1, "filename": "dyndis-0.0.3b1.post0.tar.gz", "has_sig": false, "md5_digest": "f059e87027b764ba28baf389f8d17443", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 12528, "upload_time": "2019-11-04T12:58:57", "upload_time_iso_8601": "2019-11-04T12:58:57.753706Z", "url": "https://files.pythonhosted.org/packages/09/da/34d4ac4d45867ed2110cb751237a140727519208a85884766180416d0e54/dyndis-0.0.3b1.post0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "46090528374d938a9d038baa65f942be", "sha256": "96c98951e71f16c60bebb1790c1dac5d75bb9e7463c0bee599375f9e5949eb17" }, "downloads": -1, "filename": "dyndis-0.0.4.tar.gz", "has_sig": false, "md5_digest": "46090528374d938a9d038baa65f942be", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 16527, "upload_time": "2019-11-25T14:55:36", "upload_time_iso_8601": "2019-11-25T14:55:36.898293Z", "url": "https://files.pythonhosted.org/packages/bc/85/75971cf4d5c045f8831024f644bc871bcf436a97e4e7729760b105481a8c/dyndis-0.0.4.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.4rc0": [ { "comment_text": "", "digests": { "md5": "8cda52797497cb9e48e72466766e14ff", "sha256": "c6fb76468685c9c1c16ccdbb9bd99b59dea23948bb400a9e95a8892899f000da" }, "downloads": -1, "filename": "dyndis-0.0.4rc0.tar.gz", "has_sig": false, "md5_digest": "8cda52797497cb9e48e72466766e14ff", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 14492, "upload_time": "2019-11-21T12:35:30", "upload_time_iso_8601": "2019-11-21T12:35:30.855790Z", "url": "https://files.pythonhosted.org/packages/9b/7c/d0ac613871d9c2dd5ab71c2a5755e304f32fa7784078fcc48a11ecfdc6e8/dyndis-0.0.4rc0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "c90137ba50cb8ef9f0b80e245de52736", "sha256": "fcf27b589db74b97bd0d7231338cebb90b62db1a18383fffe13e0b9382439209" }, "downloads": -1, "filename": "dyndis-0.0.5.tar.gz", "has_sig": false, "md5_digest": "c90137ba50cb8ef9f0b80e245de52736", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 14654, "upload_time": "2019-12-10T12:39:14", "upload_time_iso_8601": "2019-12-10T12:39:14.403685Z", "url": "https://files.pythonhosted.org/packages/24/92/a7771479d3bc53f343a01ed96f67253b0978ae35ae674219b54de383a8df/dyndis-0.0.5.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "3baa195e7f21c59d8a752bfc14896177", "sha256": "38c90bdba6692cee8946e2e6a7bc9134ad653a949dc0921143f87754b2453f93" }, "downloads": -1, "filename": "dyndis-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3baa195e7f21c59d8a752bfc14896177", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 14712, "upload_time": "2020-01-20T22:27:06", "upload_time_iso_8601": "2020-01-20T22:27:06.960466Z", "url": "https://files.pythonhosted.org/packages/a2/fe/53ba3ac7271e187305ef9c5b70b17bb36156e464bf4cbda2f9e84c6d0606/dyndis-0.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.0.dev0": [ { "comment_text": "", "digests": { "md5": "4316159dc966f6c93e824defa83e9e44", "sha256": "1c6870d839e105d800df8d369b28ffcc9e53ddb60efabc7331d2ce42fd844109" }, "downloads": -1, "filename": "dyndis-0.1.0.dev0.tar.gz", "has_sig": false, "md5_digest": "4316159dc966f6c93e824defa83e9e44", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 14713, "upload_time": "2020-01-20T22:27:04", "upload_time_iso_8601": "2020-01-20T22:27:04.990287Z", "url": "https://files.pythonhosted.org/packages/89/d6/fea62305abfa64b66eb4110c370b83e619494534eee6647f45d419dc77d2/dyndis-0.1.0.dev0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "3146b1cd4c7fe186e4ff8b6ea6e50c4f", "sha256": "babf5d30f78fdc9b5f8604fb40efed5813e0a5336603e4c4fc5527cffc5f849b" }, "downloads": -1, "filename": "dyndis-0.1.1.tar.gz", "has_sig": false, "md5_digest": "3146b1cd4c7fe186e4ff8b6ea6e50c4f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 20521, "upload_time": "2020-01-20T22:29:37", "upload_time_iso_8601": "2020-01-20T22:29:37.782797Z", "url": "https://files.pythonhosted.org/packages/73/d7/fbc6122ef788baf5d32a871cf568d5830b96ba7666542db48ce9c992c337/dyndis-0.1.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "38d0b866147d3170b593e3c85e8d7ad2", "sha256": "f675698fc75f8b9ecce4113b99df24ede10fda581c67adc1c35727832e361889" }, "downloads": -1, "filename": "dyndis-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "38d0b866147d3170b593e3c85e8d7ad2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 10383, "upload_time": "2020-12-20T18:28:37", "upload_time_iso_8601": "2020-12-20T18:28:37.442225Z", "url": "https://files.pythonhosted.org/packages/27/a8/a65d7c275d1dbc24404e798d77ab6cf24370087d8520a6b73e4b2e8153b8/dyndis-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "a537f4000901ed3a34ca10d9669e2c2a", "sha256": "703d6efd4768e992689f119143fdf109cd0f1bee8fd58292f49d1abdeb2626dd" }, "downloads": -1, "filename": "dyndis-0.2.0.tar.gz", "has_sig": false, "md5_digest": "a537f4000901ed3a34ca10d9669e2c2a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 11230, "upload_time": "2020-12-20T18:28:38", "upload_time_iso_8601": "2020-12-20T18:28:38.723490Z", "url": "https://files.pythonhosted.org/packages/19/aa/5c05f4c1236448975b687064ad2782f0a56ed3ee8cf9406cd87e8f9e7881/dyndis-0.2.0.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "38d0b866147d3170b593e3c85e8d7ad2", "sha256": "f675698fc75f8b9ecce4113b99df24ede10fda581c67adc1c35727832e361889" }, "downloads": -1, "filename": "dyndis-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "38d0b866147d3170b593e3c85e8d7ad2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 10383, "upload_time": "2020-12-20T18:28:37", "upload_time_iso_8601": "2020-12-20T18:28:37.442225Z", "url": "https://files.pythonhosted.org/packages/27/a8/a65d7c275d1dbc24404e798d77ab6cf24370087d8520a6b73e4b2e8153b8/dyndis-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "a537f4000901ed3a34ca10d9669e2c2a", "sha256": "703d6efd4768e992689f119143fdf109cd0f1bee8fd58292f49d1abdeb2626dd" }, "downloads": -1, "filename": "dyndis-0.2.0.tar.gz", "has_sig": false, "md5_digest": "a537f4000901ed3a34ca10d9669e2c2a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 11230, "upload_time": "2020-12-20T18:28:38", "upload_time_iso_8601": "2020-12-20T18:28:38.723490Z", "url": "https://files.pythonhosted.org/packages/19/aa/5c05f4c1236448975b687064ad2782f0a56ed3ee8cf9406cd87e8f9e7881/dyndis-0.2.0.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }