{ "info": { "author": "Ihor Kalnytskyi", "author_email": "ihor@kalnytskyi.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Python Software Foundation License", "Operating System :: OS Independent", "Programming Language :: Python", "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", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries" ], "description": "singledispatchmethod\n====================\n\nBackport of ``@functools.singledispatchmethod`` decorator [1]_ from\nPython 3.8 to Python 2.7-3.7. These are merely ~30 lines of code, but\nwhy bother yourself with copypasta?\n\n.. code:: bash\n\n $ pip install singledispatchmethod\n\nThe decorator transforms a method into a single-dispatch [2]_ generic\nfunction [3]_. Note that since the dispatch happens on the type of the\nfirst non-self or non-cls argument, you have to create your function\naccordingly:\n\n.. code:: python\n\n from singledispatchmethod import singledispatchmethod\n\n class Negator:\n\n @singledispatchmethod\n def neg(self, arg):\n raise NotImplementedError(\"Cannot negate a\")\n\n @neg.register\n def _(self, arg: int):\n return -arg\n\n @neg.register\n def _(self, arg: bool):\n return not arg\n\n``@singledispatchmethod`` supports nesting with other decorators such as\n``@classmethod``. However, in order to expose ``dispatcher.register``,\n``@singledispatchmethod`` must be the *outer most* decorator. Here is\nthe ``Negator`` class with the ``neg`` methods being class bound:\n\n.. code:: python\n\n from singledispatchmethod import singledispatchmethod\n\n class Negator:\n\n @singledispatchmethod\n @classmethod\n def neg(cls, arg):\n raise NotImplementedError(\"Cannot negate a\")\n\n @neg.register\n @classmethod\n def _(cls, arg: int):\n return -arg\n\n @neg.register\n @classmethod\n def _(cls, arg: bool):\n return not arg\n\nThe same pattern can be used for other similar decorators, such as\n``@staticmethod`` or ``@abstractmethod``. Please note, since\n``@singledispatchmethod`` decorator is based on\n``@functools.singledispatch``, type annotations are supported by\n``dispatcher.register`` only since Python 3.7.\n\n.. [1] https://docs.python.org/3.8/library/functools.html#functools.singledispatchmethod\n.. [2] https://docs.python.org/3.8/glossary.html#term-single-dispatch\n.. [3] https://docs.python.org/3.8/glossary.html#term-generic-function", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ikalnytskyi/singledispatchmethod", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "singledispatchmethod", "package_url": "https://pypi.org/project/singledispatchmethod/", "platform": "", "project_url": "https://pypi.org/project/singledispatchmethod/", "project_urls": { "Bugs": "https://github.com/ikalnytskyi/singledispatchmethod/issues", "Documentation": "https://docs.python.org/3.8/library/functools.html#functools.singledispatchmethod", "Homepage": "https://github.com/ikalnytskyi/singledispatchmethod", "Source": "https://github.com/ikalnytskyi/singledispatchmethod" }, "release_url": "https://pypi.org/project/singledispatchmethod/1.0/", "requires_dist": null, "requires_python": "", "summary": "Backport of @functools.singledispatchmethod to Python 2.7-3.7.", "version": "1.0" }, "last_serial": 5664451, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "d2653ccefce26ff614741cd71c2f6ec6", "sha256": "183a7fbeab53b9c9d182f8b8f9c2d7e109a7d40afaa30261d81dd8de68cd73bf" }, "downloads": -1, "filename": "singledispatchmethod-1.0.tar.gz", "has_sig": false, "md5_digest": "d2653ccefce26ff614741cd71c2f6ec6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6064, "upload_time": "2019-08-12T07:28:17", "url": "https://files.pythonhosted.org/packages/be/e0/20ecc21453d7f052ee04d0d9b3305798e0f6afc619885c9aaee4ba86b25c/singledispatchmethod-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d2653ccefce26ff614741cd71c2f6ec6", "sha256": "183a7fbeab53b9c9d182f8b8f9c2d7e109a7d40afaa30261d81dd8de68cd73bf" }, "downloads": -1, "filename": "singledispatchmethod-1.0.tar.gz", "has_sig": false, "md5_digest": "d2653ccefce26ff614741cd71c2f6ec6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6064, "upload_time": "2019-08-12T07:28:17", "url": "https://files.pythonhosted.org/packages/be/e0/20ecc21453d7f052ee04d0d9b3305798e0f6afc619885c9aaee4ba86b25c/singledispatchmethod-1.0.tar.gz" } ] }