Overload python functions to behave diffrently depending on number and types of arguments.
Install
pip install p2-overload
Usage
from overload import *
# types and number or agrs:
@overload(int)
def quantify(n):
return 'quantify' * n
@overload(str)
def quantify(s):
return s * 2
@overload(str, int)
def quantify(s, n):
return s * n
assert quantify(2) == 'quantifyquantify'
assert quantify('bye') == 'byebye'
assert quantify('xy', 3) == 'xyxyxy'
# predicates on args
@overload(int, int)
def step(start, step):
return start + step
@overload(int, callable)
def step(start, succ):
return succ(start)
# use tuple of types
@overload((list, tuple))
def twice(coll):
return coll + coll
# use custom predicates
from whatever import _
@overload(_ < 2) # same as lambda x: x < 2
def fib(n):
return n
@overload(int)
def fib(n):
return fib(n-1) + fib(n-2)
TODO
support named and optional arguments
ellipsis
Release files for p2-overload 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| p2-overload-0.1.tar.gz | 3.0 kB | Details |
Release files / p2-overload-0.1.tar.gz
| Download URL | p2-overload-0.1.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3312f723e426b77c2eaeebc539be55f305067e2fc4941d54cc417d8f34ca8e55
|
|
BLAKE2b-256 checksum How to use checksums |
e65f07d07ef3a660b2713df3a17ab8c89e06c5186b26cfab868b7f124f20e547
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |