Overload python 2 functions with decorator.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
p2-overload-0.1.tar.gz
(3.0 kB
view details)
File details
Details for the file p2-overload-0.1.tar.gz
.
File metadata
- Download URL: p2-overload-0.1.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3312f723e426b77c2eaeebc539be55f305067e2fc4941d54cc417d8f34ca8e55 |
|
MD5 | 133a76a22e020eb9b2c4e5b6a4fd0d3d |
|
BLAKE2b-256 | e65f07d07ef3a660b2713df3a17ab8c89e06c5186b26cfab868b7f124f20e547 |