trouting-0.3.3
توضیحات
Trouting (short for Type Routing) is a simple class decorator that allows to define multiple interfaces for a method that behave differently depending on input types.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | trouting-0.3.3 |
| نام | trouting |
| نسخه کتابخانه | 0.3.3 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | - |
| ایمیل نویسنده | Luca Soldaini <luca@soldaini.net> |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/trouting/ |
| مجوز | Apache-2.0 |
# Trouting

Trouting (short for Type Routing) is a simple class decorator that allows to define multiple interfaces for a method that behave differently depending on input types.
To install for PyPI trouting, run:
```bash
pip install trouting
```
The logo of trouting was generated using [Stable Diffusion](https://github.com/CompVis/stable-diffusion) with prompt *"A Kandinsky painting titled The Trout Who Routes"* and slightly edited by the author.
## Example
Imagine you want to define a class whose method behaves differently depending on whether the input is a string or an integer. You can do this with trouting as follows:
```python
from typing import Any, Union
from trouting import trouting
class MyClass:
@trouting
def add_one(self, a: Any) -> Any:
# fallback method
raise TypeError(f"Type {type(a)} not supported")
@add_one.add_interface(a=(int, float))
def add_one_int(self, a: Union[int, float]) -> float:
# a is an int or float
return float(a + 1)
@add_one.add_interface(a=str)
def add_one_str(self, a: str) -> str:
# a is a str
return a + "1"
```
Now, when using `MyClass`, the method `add_one` will behave differently depending on the input type:
```python
my_class = MyClass()
my_class.add_one(1) # returns 2.0
my_class.add_one("1") # returns "11"
my_class.add_one([1]) # raises TypeError
```
نیازمندی
| مقدار | نام |
|---|---|
| >=4.3.0 | typing-extensions |
| >=22.6.0 | black |
| >=5.10.1 | isort |
| >=0.971 | mypy |
| >=5.2 | pytest |
| >=8.4.0 | ipython |
| >=1.7.0 | autopep8 |
| >=5.0 | flake8 |
| >=0.13.0 | ipdb |
| >=22.8.1 | flake8-pyi |
| >=1.1.0 | Flake8-pyproject |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.8 | Python |
نحوه نصب
نصب پکیج whl trouting-0.3.3:
pip install trouting-0.3.3.whl
نصب پکیج tar.gz trouting-0.3.3:
pip install trouting-0.3.3.tar.gz