adding all files done so far
This commit is contained in:
61
learning/decorators/classes_decorater.py
Normal file
61
learning/decorators/classes_decorater.py
Normal file
@@ -0,0 +1,61 @@
|
||||
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!')
|
||||
Reference in New Issue
Block a user