from datetime import date
class Datepicker:
def __init__(self, date: date) -> None:
print('date object')
def __init__(self, year, month, day) -> None:
print('args')
Datepicker(date.today()) # date object
Datepicker(2020, 1, 1) # args
help(Datepicker.__init__)
Help on wrapper_descriptor:
__init__(self, date: date) -> None
__init__(self, year, month, day) -> None
from functools import singledispatch
class Test:
def __init__(self):
self.render = singledispatch(self.render)
self.render.register(str, self._render_str)
self.render.register(int, self._render_int)
def render(self, s):
raise TypeError(f"{type(s)} type isn't supported:")
def _render_str(self, s, b=None):
print("render str")
def _render_int(self, s):
print("render int")
t = Test()
>> t.render('s')
render str
>> t.render(1)
render int