Image missing.
Ovld – Efficient and featureful multiple dispatch for Python

created: May 29, 2025, 7:45 p.m. | updated: June 1, 2025, 9:35 p.m.

from ovld import ovld from ovld . dependent import Regexp from typing import Literal @ ovld def f ( x : str ): return f"The string { x !r } " @ ovld def f ( x : int ): return f"The number { x } " @ ovld def f ( x : int , y : int ): return "Two numbers!" @ ovld def f ( x : Literal [ 0 ]): return "zero" @ ovld def f ( x : Regexp [ r"^X" ]): return "A string that starts with X" assert f ( "hello" ) == "The string 'hello'" assert f ( 3 ) == "The number 3" assert f ( 1 , 2 ) == "Two numbers!" assert f ( 0 ) == "zero" assert f ( "XSECRET" ) == "A string that starts with X"Recursive exampleovld shines particularly with recursive definitions, for example tree maps or serialization. dtype == dtype @ ovld def f ( tensor : Shape [ 3 , Any ]): # Matches 3xN tensors ... @ ovld def f ( tensor : Shape [ 2 , 2 ] & Dtype [ torch .

6 months, 1 week ago: Hacker News