62 lines
1.1 KiB
Python
62 lines
1.1 KiB
Python
import sys
|
|
import os
|
|
sys.path.append(os.getcwd()) # noqa E402
|
|
from decorator import timer, debug, repeatN, repeat_partial, count_calls, \
|
|
Counter, Slow, slowDown
|
|
from dataclasses import dataclass
|
|
|
|
|
|
class TimeWaster(object):
|
|
@debug
|
|
def __init__(self, max_num: int):
|
|
super(TimeWaster, self).__init__()
|
|
self.max_num = max_num
|
|
|
|
@timer
|
|
def waste_time(self, num_times: int):
|
|
for _ in range(num_times):
|
|
sum([i ** 2 for i in range(self.max_num)])
|
|
|
|
|
|
@timer
|
|
@dataclass
|
|
class PlayingCard(object):
|
|
rank: str
|
|
suit: str
|
|
|
|
|
|
@repeatN
|
|
def say_hello(name: str):
|
|
print(f'Hello, {name}.')
|
|
|
|
|
|
@repeatN(num=5)
|
|
def say_hi(name: str):
|
|
print(f'Hi, {name}.')
|
|
|
|
|
|
@repeat_partial(num=10)
|
|
def say_yo(name: str):
|
|
print(f'Yo, {name}!')
|
|
|
|
|
|
@count_calls
|
|
def say_whee():
|
|
print('Whee!')
|
|
|
|
|
|
@Counter
|
|
def say_howdy():
|
|
print('Howdy!')
|
|
|
|
|
|
@slowDown()
|
|
def count_down(num: int):
|
|
if not isinstance(num, int):
|
|
raise TypeError("Must input an integer.")
|
|
if num >= 1:
|
|
print(num)
|
|
count_down(num - 1)
|
|
else:
|
|
print('Liftoff!')
|