Python polymorphic function declaration with obvious syntax
Project description
Python polymorphic function declaration with obvious syntax. Just use the same function name and mark each function definition with @polymorphic decorator.
Installation
pip install polypie
Requirements
Python 3.5+
typeguard (will be installed automatically)
Example
from typing import Any, Sequence
from polypie import polymorphic, PolypieException
@polymorphic
def example(a: int, b):
print('(1)')
@polymorphic
def example(a: str, b: Any):
print('(2)')
@polymorphic
def example(a: Sequence[str]):
print('(3)')
example(100, 200) # (1)
example('foo', 200) # (2)
example(['foo']) # (3)
example(('bar', 'baz')) # (3)
try:
example({'foo': 'bar'})
except PolypieException as exc:
print(exc) # Matching signature <...> not found
class Example:
def __init__(self):
self.values = {}
@polymorphic
def value(self, name):
return self.values[name]
@polymorphic
def value(self, name, value):
self.values[name] = value
instance = Example()
instance.value('foo', 100)
instance.value('bar', 'baz')
print(instance.value('foo')) # 100
print(instance.value('bar')) # baz
Tests
tox [-e ENV] [-- --cov]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
polypie-0.2.0.tar.gz
(3.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polypie-0.2.0.tar.gz.
File metadata
- Download URL: polypie-0.2.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using 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.32.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07acea8578cdb4b533d724297b3d6739b0d146cc3b004b2b7efd387b9b83f2bd
|
|
| MD5 |
60f8870460a7860f297d8f8497687419
|
|
| BLAKE2b-256 |
755d71d481fc92cbf87000060b84bd9de534a6f163609ac6ea72b8f783bb3023
|
File details
Details for the file polypie-0.2.0-py3-none-any.whl.
File metadata
- Download URL: polypie-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using 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.32.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8c584f2d60fe82586e08a9aed9e6c427b6d2b95538b4b441500b5ab3ba99508
|
|
| MD5 |
7fb7502f28719d0f61305e19c666c220
|
|
| BLAKE2b-256 |
6678ca281335f50d4981646be33d671d6b83bc2095ea291d2e00f40053c49714
|