Skip to content

Commit 0bc59cc

Browse files
committed
Added docstrings to several undocumented functions.
1 parent 2a469f4 commit 0bc59cc

File tree

7 files changed

+146
-0
lines changed

7 files changed

+146
-0
lines changed

patterns/behavioral/memento.py

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ def __init__(self, method):
5050
self.method = method
5151

5252
def __get__(self, obj, T):
53+
"""
54+
A decorator that makes a function transactional.
55+
56+
:param method: The function to be decorated.
57+
"""
5358
def transaction(*args, **kwargs):
5459
state = memento(obj)
5560
try:

patterns/creational/lazy_evaluation.py

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ def __get__(self, obj, type_):
3636

3737

3838
def lazy_property2(fn):
39+
"""
40+
A lazy property decorator.
41+
42+
The function decorated is called the first time to retrieve the result and then that calculated result is used the next
43+
time you access the value.
44+
"""
3945
attr = "_lazy__" + fn.__name__
4046

4147
@property

patterns/dependency_injection.py

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ def __init__(self):
1717
self.time_provider = datetime.datetime.now
1818
1919
def get_current_time_as_html_fragment(self):
20+
"""
21+
Returns the current time as a string in 12-hour clock format with seconds and am/pm.
22+
"""
23+
"""
24+
Returns the current time as a string in 12-hour clock format with seconds and am/pm.
25+
"""
26+
"""
27+
Returns the current time as a string in 12-hour clock format with seconds and am/pm.
28+
"""
2029
current_time = self.time_provider()
2130
current_time_as_html_fragment = "<span class=\"tinyBoldText\">{}</span>".format(current_time)
2231
return current_time_as_html_fragment
@@ -61,6 +70,15 @@ def set_time_provider(self, time_provider: Callable):
6170
self.time_provider = time_provider
6271

6372
def get_current_time_as_html_fragment(self):
73+
"""
74+
Returns the current time as a string in 12-hour clock format with seconds and am/pm.
75+
"""
76+
"""
77+
Returns the current time as a string in 12-hour clock format with seconds and am/pm.
78+
"""
79+
"""
80+
Returns the current time as a string in 12-hour clock format with seconds and am/pm.
81+
"""
6482
current_time = self.time_provider()
6583
current_time_as_html_fragment = '<span class="tinyBoldText">{}</span>'.format(
6684
current_time

patterns/other/blackboard.py

+84
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def __init__(self, blackboard):
3232
self.blackboard = blackboard
3333

3434
def run_loop(self):
35+
"""
36+
This function is a loop that runs until the progress reaches 100.
37+
It checks if an expert is eager to contribute and then calls its contribute method.
38+
"""
3539
while self.blackboard.common_state["progress"] < 100:
3640
for expert in self.blackboard.experts:
3741
if expert.is_eager_to_contribute:
@@ -50,6 +54,26 @@ def is_eager_to_contribute(self):
5054

5155
@abc.abstractmethod
5256
def contribute(self):
57+
"""
58+
This function is responsible for contributing to the common state of the project.
59+
It adds a random number between 1 and 2 to problems, between 10 and
60+
20 suggestions,
61+
and it adds this class name to contributions. It also increments progress by a random number between 10 and 100.
62+
"""
63+
"""
64+
:param self:
65+
:returns None:
66+
"""
67+
"""
68+
This function is responsible for contributing to the project.
69+
It adds a random number of problems and suggestions, as well as adding its name to the
70+
list of contributions.
71+
"""
72+
"""
73+
This function adds a random number of problems and suggestions to the common state,
74+
and also adds its name to the list of contributions. It also
75+
increments progress by a random number between 10 and 100.
76+
"""
5377
raise NotImplementedError("Must provide implementation in subclass.")
5478

5579

@@ -59,6 +83,26 @@ def is_eager_to_contribute(self):
5983
return True
6084

6185
def contribute(self):
86+
"""
87+
This function is responsible for contributing to the common state of the project.
88+
It adds a random number between 1 and 2 to problems, between 10 and
89+
20 suggestions,
90+
and it adds this class name to contributions. It also increments progress by a random number between 10 and 100.
91+
"""
92+
"""
93+
:param self:
94+
:returns None:
95+
"""
96+
"""
97+
This function is responsible for contributing to the project.
98+
It adds a random number of problems and suggestions, as well as adding its name to the
99+
list of contributions.
100+
"""
101+
"""
102+
This function adds a random number of problems and suggestions to the common state,
103+
and also adds its name to the list of contributions. It also
104+
increments progress by a random number between 10 and 100.
105+
"""
62106
self.blackboard.common_state["problems"] += random.randint(1, 10)
63107
self.blackboard.common_state["suggestions"] += random.randint(1, 10)
64108
self.blackboard.common_state["contributions"] += [self.__class__.__name__]
@@ -71,6 +115,26 @@ def is_eager_to_contribute(self):
71115
return random.randint(0, 1)
72116

73117
def contribute(self):
118+
"""
119+
This function is responsible for contributing to the common state of the project.
120+
It adds a random number between 1 and 2 to problems, between 10 and
121+
20 suggestions,
122+
and it adds this class name to contributions. It also increments progress by a random number between 10 and 100.
123+
"""
124+
"""
125+
:param self:
126+
:returns None:
127+
"""
128+
"""
129+
This function is responsible for contributing to the project.
130+
It adds a random number of problems and suggestions, as well as adding its name to the
131+
list of contributions.
132+
"""
133+
"""
134+
This function adds a random number of problems and suggestions to the common state,
135+
and also adds its name to the list of contributions. It also
136+
increments progress by a random number between 10 and 100.
137+
"""
74138
self.blackboard.common_state["problems"] += random.randint(10, 20)
75139
self.blackboard.common_state["suggestions"] += random.randint(10, 20)
76140
self.blackboard.common_state["contributions"] += [self.__class__.__name__]
@@ -83,6 +147,26 @@ def is_eager_to_contribute(self):
83147
return True if self.blackboard.common_state["problems"] > 100 else False
84148

85149
def contribute(self):
150+
"""
151+
This function is responsible for contributing to the common state of the project.
152+
It adds a random number between 1 and 2 to problems, between 10 and
153+
20 suggestions,
154+
and it adds this class name to contributions. It also increments progress by a random number between 10 and 100.
155+
"""
156+
"""
157+
:param self:
158+
:returns None:
159+
"""
160+
"""
161+
This function is responsible for contributing to the project.
162+
It adds a random number of problems and suggestions, as well as adding its name to the
163+
list of contributions.
164+
"""
165+
"""
166+
This function adds a random number of problems and suggestions to the common state,
167+
and also adds its name to the list of contributions. It also
168+
increments progress by a random number between 10 and 100.
169+
"""
86170
self.blackboard.common_state["problems"] += random.randint(1, 2)
87171
self.blackboard.common_state["suggestions"] += random.randint(10, 20)
88172
self.blackboard.common_state["contributions"] += [self.__class__.__name__]

patterns/other/graph_search.py

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ def find_shortest_path_dfs(self, start, end, path=None):
4949
return shortest
5050

5151
def find_shortest_path_bfs(self, start, end):
52+
"""
53+
Finds the shortest path between two nodes in a graph using breadth-first search.
54+
55+
:param start: The node to start from.
56+
:type start: str or int
57+
:param end: The node to find the shortest path to.
58+
:type end: str or int
59+
60+
:returns queue_path_to_end, dist_to[end]: A list of nodes
61+
representing the shortest path from `start` to `end`, and a dictionary mapping each node in the graph (except for `start`) with its distance from it
62+
(in terms of hops). If no such path exists, returns an empty list and an empty dictionary instead.
63+
"""
5264
queue = [start]
5365
dist_to = {start: 0}
5466
edge_to = {}

patterns/structural/front_controller.py

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ def __init__(self):
2222
self.tablet_view = TabletView()
2323

2424
def dispatch(self, request):
25+
"""
26+
This function is used to dispatch the request based on the type of device.
27+
If it is a mobile, then mobile view will be called and if it is a tablet,
28+
then tablet view will be called.
29+
Otherwise, an error message will be printed saying that cannot dispatch the request.
30+
"""
2531
if request.type == Request.mobile_type:
2632
self.mobile_view.show_index_page()
2733
elif request.type == Request.tablet_type:
@@ -37,6 +43,9 @@ def __init__(self):
3743
self.dispatcher = Dispatcher()
3844

3945
def dispatch_request(self, request):
46+
"""
47+
This function takes a request object and sends it to the dispatcher.
48+
"""
4049
if isinstance(request, Request):
4150
self.dispatcher.dispatch(request)
4251
else:

patterns/structural/mvc.py

+12
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ def show_items(self):
9999
self.view.show_item_list(item_type, items)
100100

101101
def show_item_information(self, item_name):
102+
"""
103+
Show information about a {item_type} item.
104+
:param str item_name: the name of the {item_type} item to show information about
105+
"""
106+
"""
107+
Show information about a {item_type} item.
108+
:param str item_name: the name of the {item_type} item to show information about
109+
"""
110+
"""
111+
Prints the information of a given item.
112+
:param str item_name: name of the item to be found
113+
"""
102114
try:
103115
item_info = self.model.get(item_name)
104116
except Exception:

0 commit comments

Comments
 (0)