Skip to main content

Overload

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

Metadata

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)

Source distribution for p2-overload 0.1
File Size Uploaded Provenance
p2-overload-0.1.tar.gz 3.0 kB Without provenance 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

Security for p2-overload 0.1

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.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page