1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.
singledispatchmethod
Backport of @functools.singledispatchmethod decorator [1] from Python 3.8 to Python 2.7-3.7. These are merely ~30 lines of code, but why bother yourself with copypasta?
$ pip install singledispatchmethod
The decorator transforms a method into a single-dispatch [2] generic function [3]. Note that since the dispatch happens on the type of the first non-self or non-cls argument, you have to create your function accordingly:
from singledispatchmethod import singledispatchmethod
class Negator:
@singledispatchmethod
def neg(self, arg):
raise NotImplementedError("Cannot negate a")
@neg.register
def _(self, arg: int):
return -arg
@neg.register
def _(self, arg: bool):
return not arg
@singledispatchmethod supports nesting with other decorators such as @classmethod. However, in order to expose dispatcher.register, @singledispatchmethod must be the outer most decorator. Here is the Negator class with the neg methods being class bound:
from singledispatchmethod import singledispatchmethod
class Negator:
@singledispatchmethod
@classmethod
def neg(cls, arg):
raise NotImplementedError("Cannot negate a")
@neg.register
@classmethod
def _(cls, arg: int):
return -arg
@neg.register
@classmethod
def _(cls, arg: bool):
return not arg
The same pattern can be used for other similar decorators, such as @staticmethod or @abstractmethod. Please note, since @singledispatchmethod decorator is based on @functools.singledispatch, type annotations are supported by dispatcher.register only since Python 3.7.
Metadata
Release files for singledispatchmethod 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release files before installing.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| singledispatchmethod-1.0.tar.gz | 6.1 kB | Without provenance | Details for singledispatchmethod-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| singledispatchmethod-1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for singledispatchmethod-1.0-py2.py3-none-any.whl |
Total release size: 10.7 kB
Release files / singledispatchmethod-1.0.tar.gz
| Download URL | singledispatchmethod-1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
183a7fbeab53b9c9d182f8b8f9c2d7e109a7d40afaa30261d81dd8de68cd73bf
|
|
BLAKE2b-256 checksum How to use checksums |
bee020ecc21453d7f052ee04d0d9b3305798e0f6afc619885c9aaee4ba86b25c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.1
|
Release files / singledispatchmethod-1.0-py2.py3-none-any.whl
File added late
This file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release file before installing.
| Download URL | singledispatchmethod-1.0-py2.py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
ed4a794e701cbe415f0df32b71dbdb96d3a415701795bcfb5ee694f8c12418db
|
|
BLAKE2b-256 checksum How to use checksums |
c4aecb1b0901b332754245ce6ce900beef6e6c6a97b42e1e4eb78ab66379a6ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for singledispatchmethod 1.0
Upload timing
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.