Skip to content

Commit 1f2bb45

Browse files
authored
Merge pull request #386 from mjanos5/trelent-documentation
Added docstrings to several undocumented functions
2 parents 84fa121 + 75d3ec0 commit 1f2bb45

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed

patterns/behavioral/memento.py

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ 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+
"""
58+
5359
def transaction(*args, **kwargs):
5460
state = memento(obj)
5561
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
43+
then that calculated result is used the next time you access the value.
44+
"""
3945
attr = "_lazy__" + fn.__name__
4046

4147
@property

patterns/other/blackboard.py

+4
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:

patterns/other/graph_search.py

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ 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
62+
mapping each node in the graph (except for `start`) with its distance from it
63+
(in terms of hops). If no such path exists, returns an empty list and an empty
64+
dictionary instead.
65+
"""
5266
queue = [start]
5367
dist_to = {start: 0}
5468
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

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ 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+
"""
102106
try:
103107
item_info = self.model.get(item_name)
104108
except Exception:

0 commit comments

Comments
 (0)