https://github.com/bindreams/overload
Overload functions in python.
https://github.com/bindreams/overload
overloading python3
Last synced: about 1 year ago
JSON representation
Overload functions in python.
- Host: GitHub
- URL: https://github.com/bindreams/overload
- Owner: bindreams
- Created: 2020-09-24T07:08:47.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-09T13:21:26.000Z (over 4 years ago)
- Last Synced: 2024-03-30T13:26:17.439Z (about 2 years ago)
- Topics: overloading, python3
- Language: Cython
- Homepage:
- Size: 293 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# overload
A python package that makes it possible to overload functions.
An overloaded function has several signatures and definitions, one of which is picked depending on the arguments:
```python
@overload
def position(x, y):
print(f"({x}, {y})")
@overload
def position(t: tuple):
print(f"({t[0]}, {t[1]})")
@overload
def position(pos: QPoint):
print(f"{pos.x()}, {pos.y()}")
position(1, 2) # Picks overload 1
position((1, 2)) # Picks overload 2
position(QPoint()) # Picks overload 3
```
## Installation
The recommended method of installation is through pip:
```
pip install https://github.com/andreasxp/overload/archive/master.zip
```
Since this package is not yet published on PyPI, installing from Github is the only option.
## Usage
Import `overload` from the package:
```python
from overload import overload
```
Use it to overload functions or methods:
```python
class Texture:
@overload
def __init__(self, color: int):
# create texture from a color code
@overload
def __init__(self, image_path: str):
# create texture from an image
```
```python
@overload
def print_sequence(*items):
print(", ".join(items))
@overload
def print_sequence(seq: list):
print_sequence(*seq)
```