![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
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.
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:
pip install trouting
The logo of trouting was generated using Stable Diffusion with prompt "A Kandinsky painting titled The Trout Who Routes" and slightly edited by the author.
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:
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:
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
FAQs
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.
We found that trouting demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.