Skip to content

Instantly share code, notes, and snippets.

Last active May 2, 2021
What would you like to do?
Worked example of overloading
import math
from functools import singledispatch
class Square:
length: int
def __init__(self, length=0):
self.length = length
class Circle:
radius: int
def __init__(self, radius=0):
self.radius = radius
from functools import singledispatch
def area(any_object):
raise NotImplementedError
def _(any_object):
return math.pi * (math.pow(any_object.radius, 2))
def _(any_object):
return (math.pow(any_object.length, 2))
my_circle = Circle(6)
my_square = Square(12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment